美文网首页
UI--UILable

UI--UILable

作者: 心如止水的鱼 | 来源:发表于2017-11-07 16:23 被阅读0次

前言:UI控件整理之UILable

一、UILabel 效果图基本代码实现

效果图

UILabel *titleLa = [[UILabel alloc]init];

titleLa.frame = CGRectMake(20, 60, [UIScreen mainScreen].bounds.size.width - 40, 40);

titleLa.text = @"UILable";

titleLa.textColor = [UIColor redColor];

titleLa.backgroundColor = [UIColor blackColor];

titleLa.font = [UIFont fontWithName:@"IowanOldStyle-Roman" size:30];

titleLa.textAlignment = NSTextAlignmentCenter;

[self.view addSubview:titleLa];

二、部分常用属性解析

1、自动换行

[titleLa setNumberOfLines:0];//设置设置行数为0

[titleLa setLineBreakMode:NSLineBreakByWordWrapping];//设置换行模式

2、自适应宽度(将字体缩放,以致所有的文字都显示全)

[titleLa setAdjustsFontSizeToFitWidth:YES];

3、自适应大小(配合自动转行使用)

[titleLa sizeToFit];

4、文字的对齐方式

titleLa.textAlignment=NSTextAlignmentLeft;     左对齐(默认)

titleLa.textAlignment=NSTextAlignmenCenter;   居中

titleLa.textAlignment=NSTextAlignmentRight;    右对齐

三、常用拓展

UIFont是UI字体类

1、系统默认常规 UIFont * font = [UIFont systemFontOfSize:15];

2、系统默认粗体 UIFont * font1 = [UIFont boldSystemFontOfSize:15];

3、系统默认斜体 UIFont * font2 = [UIFont italicSystemFontOfSize:15];

4、指定系统字体或自定义字体 [UIFont fontWithName:@"IowanOldStyle-Roman" size:30];

拿到当前系统支持的所有的字体名:

NSArray * allFontName = [UIFont familyNames];

NSLog(@"%@", allFontName);

四、补充

1、UILable用户交互默认值是NO

2、阴影

titleLa.shadowColor=[UIColor   greenColor];//文字阴影颜色的设置

titleLa.shadowOffset=CGSizeMake(3,3);//文字阴影的大小设置

3、边框

titleLa.layer.borderColor =[UIColor blackColor].CGColor;//边框颜色

titleLa.layer.borderWidth = 1;//边框宽度

titleLa.layer.cornerRadius = 10;//设置边框圆角角度

4、行间距(富文本实现)

NSString *descStr = @"UILableUILableUILableUILableUILableUILableUILable";

NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:descStr];

NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];

[paragraphStyle setLineSpacing:15];//调整行间距大小

[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [descStr length])];

titleLa.attributedText = attributedString;

效果图

相关文章

  • UI--UILable

    前言:UI控件整理之UILable 一、UILabel 效果图基本代码实现 UILabel *titleLa = ...

网友评论

      本文标题:UI--UILable

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