UILabel计算行间距&高度
2015-09-16 17:04
330 查看
计算字符串在label中的行间距
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 100, 300, 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:10];//调整行间距大小 [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [labelText length])]; label.attributedText = attributedString; [self.view addSubview:label]; [label sizeToFit];
计算Label的高度,这个是按纯文字来算的
NSString *labelText = @"可以自己按照宽高,字体大小,来计算有多少行。。然后。。。每行画一个UILabel。。高度自己可以控制把这个写一个自定义的类。 "; UIFont *font = [UIFont fontWithName:@"Helvetica" size:17]; CGSize constraintSize = CGSizeMake(200, 200); CGSize lableSize = [labelText sizeWithFont:font constrainedToSize:constraintSize lineBreakMode:NSLineBreakByCharWrapping]; NSLog(@"height----->%f",lableSize.height);
相关文章推荐
- UINavigationController
- Android BLE 蓝牙低功耗教程,中央BluetoothGatt和周边BluetoothGattServer的实现
- 编码实现简单UI界面
- 学习笔记:UITabBarController使用详解
- CodeForces-266B Queue at the School
- HBuilder打包ios应用
- AI-N Queen Problem(bfs)
- AI-N Queen Problem(dfs)
- JS获取URL中参数值(QueryString)的4种方法分享
- EasyUI,comobox兼容可编辑和和下拉框
- `MQTTClient (~> 0.2.6)` required by `Podfile`
- 3.0新成员 -value,vector,map
- Sphinx/Coreseek 4.1 跑 buildconf.sh 一个错误,无法生成configure档
- 利用Global 的BeginRequest事件实现域名的重写
- HDU 4746 Mophues(莫比乌斯反演)
- 产品交互设计入门书籍推荐(亲自看过)
- UGUI之slider详解
- iOS UItextField 总结
- Using 1.7 requires compiling with Android 4.4 (KitKat); currently using API XX
- Auto Layout still required after sending -viewDidLayoutSubviews to the view controller. 终极解决方法