调整UILabel行高间距(利用iOS 6的特性来手动调整行间矩)
2015-08-28 15:24
393 查看
http://www.cocoachina.com/bbs/read.php?tid=178403
#define LINESPACE 20
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 100, 320, 200)];
[label setBackgroundColor:[UIColor blackColor]];
[label setTextColor:[UIColor whiteColor]];
[label setNumberOfLines:0];
NSString *labelText = @"可以自己按照宽高,字体大小,来计算有多少行。。然后。。。每行画一个UILabel。。高度自己可以控制把这个写一个自定义的类。 ";
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:LINESPACE];//调整行间距
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0,
[labelText length])];
label.attributedText = attributedString;
[self.view addSubview:label];
[label sizeToFit];
![](http://cdn.cocimg.com/bbs/attachment/Fid_21/21_2069_0571ac5c5f282e7.png)
![](http://cdn.cocimg.com/bbs/attachment/Fid_21/21_2069_f695b9ec1f078e8.png)
#define LINESPACE 20
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 100, 320, 200)];
[label setBackgroundColor:[UIColor blackColor]];
[label setTextColor:[UIColor whiteColor]];
[label setNumberOfLines:0];
NSString *labelText = @"可以自己按照宽高,字体大小,来计算有多少行。。然后。。。每行画一个UILabel。。高度自己可以控制把这个写一个自定义的类。 ";
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:LINESPACE];//调整行间距
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0,
[labelText length])];
label.attributedText = attributedString;
[self.view addSubview:label];
[label sizeToFit];
![](http://cdn.cocimg.com/bbs/attachment/Fid_21/21_2069_0571ac5c5f282e7.png)
![](http://cdn.cocimg.com/bbs/attachment/Fid_21/21_2069_f695b9ec1f078e8.png)
![](http://cdn.cocimg.com/bbs/attachment/Fid_21/21_2069_5f3107c4fd002df.png)
相关文章推荐
- UIImagePickerController拍照与摄像
- LeetCode-Distinct Subsequences
- easyui之datagrid动态修改列
- UGUI之判断是否点在UI上
- hdu 2227Find the nondecreasing subsequences(树状数组+dp+离散化)
- 【Material Design视觉设计语言】UI组件设计(八):列表
- iOS 三级UIPickerView使用
- [Usaco2005][BZOJ1674] Part Acquisition|dijkstra|priority_queue
- UINavigation_Bar
- iOS---UICollectionView详解和常用API翻译
- 【Material Design视觉设计语言】UI组件设计(七):网格
- 关于UIAutomator 滚动的steps
- iOS开发——高级篇——iOS键盘的相关设置(UITextfield)
- mysql数据库优化 pt-query-digest使用
- UILabel右边缘黑线问题
- mysql 必须掌握的工具pt-query-digest安装
- 图片拉伸 [UIImage resizableImageWithCapInsets:]使用注意
- NSIS DerectUI 皮肤插件 免费使用!!支持异性,动画!!
- UITableViewCell 的重叠
- cmake的四个命令:add_compile_options()add_definitions()target_compile_definitions()build_command()