关于UILabel

iOS第二天

1、UILabel

**//设置文字
label.text = @”欢迎收看灌篮高手,我是安溪教练”;
**//设置文字颜色
label.textColor = [UIColor grayColor];
**//默认17号字体
label.font = [UIFont systemFontOfSize:34];
**//对齐方式
label.textAlignment = NSTextAlignmentCenter;
**//设置阴影
label.shadowColor = [UIColor redColor];
//设置阴影映射大小(坐标),默认CGSizeMake(0, -1)
label.shadowOffset = CGSizeMake(-2, -2);
*//断句,展示缩略
label.lineBreakMode = NSLineBreakByTruncatingTail;
**//行数0为自动匹配行数
label.numberOfLines = 1;
*//字体是否适应宽度(Size无效)(将宽度充满)
label.adjustsFontSizeToFitWidth = YES;
//最小字体比例(缩放)
label.minimumScaleFactor = 0.9;
**//label背景色
label.backgroundColor = [UIColor yellowColor];
//设置高亮颜色
label.highlightedTextColor = [UIColor greenColor];
//开启高亮状态
label.highlighted = YES;
//是否隐藏高亮状态
label.hidden = NO;
2、UIFont

//打印苹果自带字体

for (NSString* str in [UIFont familyNames]) {
NSLog(@”%@”,str);

   NSArray* arr = [UIFont fontNamesForFamilyName:str];
    for (NSString* str1 in arr) {
        NSLog(@"%@",str1);
    }
}

//斜体
[UIFont italicSystemFontOfSize:50];
//字体加粗
[UIFont boldSystemFontOfSize:50];
//设置系统字体
[UIFont systemFontOfSize:10];
//设置自定义字体

[UIFont fontWithName:@”Heiti TC” size:25];

//修改字体
[[UIFont systemFontOfSize:10] fontWithSize:50];

富文本

3、NSAttributedString

NSAttributedString * attribute = [[NSAttributedString alloc] initWithString:string attributes:dictA];

label.attributedText = attribute;

addAttributes//分段操作字符串
(字典类型)
NSFontAttributeName:[UIFont systemFontOfSize:20],//字体大小

NSForegroundColorAttributeName:[UIColor greenColor]//字体颜色

NSBackgroundColorAttributeName:[UIColor grayColor]//字体背景颜色

NSParagraphStyleAttributeName:paragraph//段落属性

NSObliquenessAttributeName:@0.5 //斜体

NSStrokeColorAttributeName:[UIColor whiteColor],//边线颜色

NSStrokeWidthAttributeName:@2,//描边

NSKernAttributeName:@20,//字间距

NSStrikethroughStyleAttributeName:@2,//删除线
NSUnderlineStyleAttributeName:@1, //下划线

段落
4、NSMutableParagraphStyle 属性
//行间距

paragraph.lineSpacing = 10;

//段间距

paragraph.paragraphSpacing = 50;

//头尾间距(第一行)

paragraph.firstLineHeadIndent = 50;

计算label高度
CGSize size1 =[string boundingRectWithSize:CGSizeMake(self.view.frame.size.width-40, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;

竖直文本Size计算
CGSize size = [string boundingRectWithSize:CGSizeMake(字体大小, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;

自适应

  • sizeToFit

  • sizeThatFits:(CGSize)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值