#import <UIKit/UIKit.h>

@interface UILabel (Create)

/**
* 创建普通Label
*
* @param frame frame
* @param text text
* @param font font
* @param textColor textColor
* @param backgroudColor backgroudColor
* @param textAlignment textAlignment
*
* @return UILabel
*/
+ (UILabel *)createLabelWithFrame:(CGRect)frame text:(NSString *)text font:(UIFont *)font textColor:(UIColor *)textColor backgroudColor:(UIColor *)backgroudColor textAlignment:(NSTextAlignment)textAlignment; /**
* 创建自增高Label
*
* @param frame frame
* @param text text
* @param font font
* @param textColor textColor
* @param backgroudColor backgroudColor
* @param textAlignment textAlignment
*
* @return UILabel
*/
+ (UILabel *)createAdjustsLabelWithFrame:(CGRect)frame text:(NSString *)text font:(UIFont *)font textColor:(UIColor *)textColor backgroudColor:(UIColor *)backgroudColor textAlignment:(NSTextAlignment)textAlignment; @end #import "UILabel+Create.h" @implementation UILabel (Create) + (UILabel *)createLabelWithFrame:(CGRect)frame text:(NSString *)text font:(UIFont *)font textColor:(UIColor *)textColor backgroudColor:(UIColor *)backgroudColor textAlignment:(NSTextAlignment)textAlignment
{
UILabel *label = [[UILabel alloc]initWithFrame:frame];
label.text = text;
[label setFont:font];
[label setTextColor:textColor];
if (backgroudColor == nil) {
[label setBackgroundColor:[UIColor clearColor]];
}
else{
[label setBackgroundColor:backgroudColor];
}
[label setTextAlignment:textAlignment];
label.numberOfLines = ; return label;
} + (UILabel *)createAdjustsLabelWithFrame:(CGRect)frame text:(NSString *)text font:(UIFont *)font textColor:(UIColor *)textColor backgroudColor:(UIColor *)backgroudColor textAlignment:(NSTextAlignment)textAlignment
{
UILabel *label = [[UILabel alloc]initWithFrame:frame];
label.text = text;
[label setFont:font];
[label setTextColor:textColor];
if (backgroudColor == nil) {
[label setBackgroundColor:[UIColor clearColor]];
}
else{
[label setBackgroundColor:backgroudColor];
}
[label setTextAlignment:textAlignment];
label.numberOfLines = ; CGSize maxNameLabelSize = CGSizeMake(frame.size.width,);
CGSize labelSize;
labelSize = [text boundingRectWithSize:maxNameLabelSize
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName:font}
context:nil].size;
[label setFrame:CGRectMake(frame.origin.x, frame.origin.y, labelSize.width, labelSize.height)]; return label;
} // 使用
[self.view addSubview:[UILabel createLabelWithFrame:CGRectMake(, , self.view.frame.size.width-, ) text:_str font:[UIFont systemFontOfSize:.f] textColor:[UIColor redColor] backgroudColor:[UIColor clearColor] textAlignment:NSTextAlignmentLeft]];

UILabel+Create的更多相关文章

  1. 利用cocostudio库函数 实现左右滑动的背包栏UI (cocos2d-x 2.2.0)

    .h #ifndef __COMMON_COMPONENTS__ #define __COMMON_COMPONENTS__ #include "cocos2d.h" #inclu ...

  2. NGUI学习笔记(一)UILabel介绍

    来个前言: 作为一个U3D程序员,自然要写一写U3D相关的内容了.想来想去还是从UI开始搞起,可能这也是最直观同时也最重要的部分之一了.U3D自带的UI系统,也许略坑,也没有太多介绍的价值,那么从今天 ...

  3. UITextField和一个UILabel绑定 浅析

    转载自:http://fengdeng.github.io/blog/2016/01/22/rxswift-dao-di-%5B%3F%5D-ge-uitextfieldshi-ru-he-he-%5 ...

  4. [Xcode 实际操作]四、常用控件-(5)UILabel文本标签自定义文字样式

    目录:[Swift]Xcode实际操作 本文将演示给标签对象添加描边效果,在项目文件夹上,点击鼠标右键菜单, 选择[Create File]->[Cocoa Touch Class]->[ ...

  5. IOS 为UILabel添加长按复制功能

    IOS 为UILabel添加长按复制功能 在iOS中下面三个控件,自身就有复制-粘贴的功能: 1.UITextView 2.UITextField 3.UIWebView UIKit framewor ...

  6. IOS --关于粘贴板 ,剪切板 ,UILabel的复制

    在iOS中下面三个控件,自身就有复制-粘贴的功能: 1.UITextView 2.UITextField 3.UIWebView UIKit framework提供了几个类和协议方便我们在自己的应用程 ...

  7. 记一次tomcat线程创建异常调优:unable to create new native thread

    测试在进行一次性能测试的时候发现并发300个请求时出现了下面的异常: HTTP Status 500 - Handler processing failed; nested exception is ...

  8. Could not create SSL connection through proxy serve-svn

    RA layer request failedsvn: Unable to connect to a repository at URL xxxxxx 最后:Could not create SSL ...

  9. android 使用Tabhost 发生could not create tab content because could not find view with id 错误

    使用Tabhost的时候经常报:could not create tab content because could not find view with id 错误. 总结一下发生错误的原因,一般的 ...

随机推荐

  1. (转)iOS7界面设计规范(8) - UI基础 - 术语和措辞

    讨厌周一,讨厌一周.今天中午交互组聚餐,却很开心:大家都是很厉害的人,你可以感到他们身上的能量,可以感到有些什么东西正在推着自己尽力向前走.这是一种很健康的状态,同时也很难得,自然越发需要珍惜.从无到 ...

  2. HDU--1584--蜘蛛牌--深搜版本号

    蜘蛛牌 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  3. QT正则表达式---针对IP地址

    判断合法IP的QT正则表达式: bool IsIPaddress(QString ip) { QRegExp rx2("(//d+)(//.)(//d+)(//.)(//d+)(//.)(/ ...

  4. keepalived vip漂移基本原理及选举算法

    keepalived可以将多个无状态的单点通过虚拟IP(以下称为VIP)漂移的方式搭建成一个高可用服务,常用组合比如 keepalived+nginx,lvs,haproxy和memcached等.它 ...

  5. contenteditable 属性

    定义和用法 contenteditable 属性规定是否可编辑元素的内容. 语法 <element contenteditable="value"> 属性值 值 描述 ...

  6. PL/SQL中字符串变量的分割转化

    在编写PL/SQL时,有时候我们需要处理这样一个输入的变量,它的格式是由多个值通过分隔符组成的字符串,如“1,2,3”,我们需要将这个变量加入到我们的SQL中,形成诸如in('1','2','3')的 ...

  7. Silverlight Visifire控件应用去水印

    版本几之前可以用属性直接去掉水印: chart.Watermark = false; 现在我用的会报错,已过时,在网上查了写资料,解决办法如下: 一.很多人都是利用摭罩的办法,定位到水印显示的地方,建 ...

  8. 2、shell命令学习

    1.第一个例子 touch test.sh vim test.sh #!/bin/bash echo "hello world" chmod 755 test.sh ./test. ...

  9. visual studio 未将对象引用设置到对象的实例

    我今天在win10上安装了Visual Studio 2015,结果新建项目后在模板中选择一项后就会弹出一个对话框: 查了许多种方法后,下面这个方法解决了我这个问题: 著作权归作者所有.商业转载请联系 ...

  10. c++11-bind的用法

    bind函数 在c++11之前,要绑定某个函数.函数对象或者成员函数的不同参数值需要用到不同的转换器,如bind1st.bind2nd.fun_ptr.mem_fun和mem_fun_ref等.在c+ ...