网站首页 美食营养 游戏数码 手工爱好 生活家居 健康养生 运动户外 职场理财 情感交际 母婴教育 时尚美容

iOS 设置label的行间距教程

时间:2024-10-12 07:43:48

1、创建一个普通的label用来对比效果 UILabel *label = [[UILabel alloc]init]; label.frame=CGRectMake(10, 50, 70, 60); label.text=@"修改前\n行间距"; label.numberOfLines=2; label.backgroundColor=[UIColor grayColor]; label.textColor=[UIColor blackColor]; [self.view addSubview:label];

iOS 设置label的行间距教程

3、 //方式二 UILabel *label3 = [[UILabel alloc]init]; label3.frame=CGRectMake(200, 50, 70, 60); label3.text=@"修改后\n行间距"; label3.numberOfLines=2; label3.backgroundColor=[UIColor grayColor]; label3.textColor=[UIColor blackColor]; [self.view addSubview:label3]; //通过修改文本属性 NSMutableAttributedString *attriString = [[NSMutableAttributedString alloc] initWithString:label3.text]; NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; [paragraphStyle setLineSpacing:10];//设置距离 [attriString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [label3.text length])]; label3.attributedText = attriString;

iOS 设置label的行间距教程
© 2025 五度知识库
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com