IOS-UILabel
属性介绍
//设置显示文字
label1.text = @"label1";
//设置字体
label1.font = [UIFont SystemFontOfSize:20];
//设置字体:粗体
label1.font = [UIFont boldSystemFontOfSize:20];
//设置文字颜色
label1.textColor = [UIColor orangeColor];
label2.textColor = [UIColor purpleColor];
//设置背景颜色
UIlabel.backgroudColor=[UIColor clearColor]; //可以去掉背景色
//设置文字位置
label1.textAlignment = UITextAlignmentRight;
label2.textAlignment = UITextAlignmentCenter;
//设置字体大小适应label宽度
label4.adjustsFontSizeToFitWidth = YES;
//设置label的行数,如果是0表示显示所有文字
label5.numberOfLines = 2;
//设置高亮
label6.highlighted = YES;
label6.highlightedTextColor = [UIColor orangeColor];
//设置阴影
label7.shadowColor = [UIColor redColor];
label7.shadowOffset = CGSizeMake(1.0,1.0);
//设置是否能与用户进行交互
label7.userInteractionEnabled = YES;
//设置label中的文字是否可变,默认值是YES
label3.enabled = NO;
//设置文字过长时的显示格式
label3.lineBreakMode = NSLineBreakByTruncatingMiddle;//截去中间
typedef NS_ENUM(NSInteger, NSLineBreakMode) {
NSLineBreakByWordWrapping = 0, //以单词为显示单位显示,后面部分省略不显示。
NSLineBreakByCharWrapping, //以字符为显示单位显示,后面部分省略不显示。
NSLineBreakByClipping,//剪切与文本宽度相同的内容长度,后半部分被删除。
NSLineBreakByTruncatingHead,//前面部分文字以……方式省略,显示尾部文字内容。
NSLineBreakByTruncatingTail,//结尾部分的内容以……方式省略,显示头的文字内容。
NSLineBreakByTruncatingMiddle //中间的内容以……方式省略,显示头尾的文字内容
};
显示不同的字体和颜色
self.title = @"For iOS 6 & later";
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Using NSAttributed String"];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,5)];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6,12)];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(19,6)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial-BoldItalicMT" size:30.0] range:NSMakeRange(0, 5)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:30.0] range:NSMakeRange(6, 12)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Courier-BoldOblique" size:30.0] range:NSMakeRange(19, 6)];
attrLabel.attributedText = str;
[参考文档]
http://www.cnblogs.com/maxfong/articles/2216180.html
http://www.cnblogs.com/ygm900/archive/2013/05/19/3086902.html
http://my.oschina.net/CarlHuang/blog/138363?fromerr=gJcPdeNY