UILabel

作者: Kyniii | 来源:发表于2017-09-05 17:02 被阅读0次

ShadowColor 设置阴影颜色

设置阴影颜色

[ label setShadowColor : [UIColor blackColor] ] ;

设置阴影偏移量

[ label setShadowOffset : CGSizeMake ( -1 ,  -1 ) ] ;

baselineAdjustment  控制文本基线的行为

label.adjustsFontSizeToFitWidth = YES;

label.baselineAdjustment = UIBaselineAdjustmentNone;  // 文本最低端与label中线对齐

                                                UIBaselineAdjustmentAlignCenters // 文本中线与label中线对齐

                                                UIBaselineAdjustmentAlignBaselines // 文本最上端与中线对齐

adjustsLetterSpacingToFitWidth 改变字母之间的间距来适应Label大小

label.adjustsLetterSpacingToFitWidth =NO;

adjustsFontSizeToFitWidth 设置字体大小适应label宽度

label.adjustsFontSizeToFitWidth =YES;

lineBreakMode 设置文字过长时的显示格式

label.lineBreakMode = NSLineBreakByCharWrapping;以字符为显示单位显示,后面部分省略不显示。

                                        NSLineBreakByClipping;剪切与文本宽度相同的内容长度,后半部分被删除。

                                        NSLineBreakByTruncatingHead;前面部分文字以……方式省略,显示尾部文字内容。

                                        NSLineBreakByTruncatingMiddle;中间的内容以……方式省略,显示头尾的文字内容。

                                        NSLineBreakByTruncatingTail;结尾部分的内容以……方式省略,显示头的文字内容。

                                        NSLineBreakByWordWrapping;以单词为显示单位显示,后面部分省略不显示。

attributedText 设置标签属性文本

NSString *text = @"Hello World";

NSMutableAttributedString *textLabelStr  = [ [NSMutableAttributedString alloc] initWithString:text ] ;

[textLabelStr setAttributes:@{NSForegroundColorAttributeName :[UIColor redColor], NSFontAttributeName :[UIFont systemFontOfSize:20]} range:NSMakeRange(1,2)];

label.attributedText = textLabelStr ;

UILabel 根据字数多少自动实现适应高度

UILabel*label = [[UILabelalloc] initWithFrame:CGRectMake(0,0,0,0)];

label.numberOfLines =0;

NSDictionary*attributes = @{NSFontAttributeName:[UIFontsystemFontOfSize:20]};

NSString*str =@"UILabel根据字数多少自动实现适应高度UILabel根据字数多少自动实现适应高度UILabel根据字数多少自动实现适应高度";

CGSizetextSize = [str boundingRectWithSize : CGSizeMake(100,100) options : NSStringDrawingTruncatesLastVisibleLineattributes:attributes context:nil].size;

[label setFrame:CGRectMake(100,100, textSize.width, textSize.height)];

label.textColor = [UIColor redColor];

label.text = str;

相关文章

网友评论

      本文标题:UILabel

      本文链接:https://www.haomeiwen.com/subject/eqgujxtx.html