获取UILabel宽度的方法
2016-06-28 01:32
489 查看
/**
获取 label 的宽度
@param fontType 0:正常 1:粗体 2:斜体
*/
- (CGFloat)getLabelWidth:(NSString *)text fontSize:(CGFloat)fontSize type:(NSInteger)fontType
{
UILabel *label = [[UILabel alloc] init];
label.text = text;
switch (fontType)
{
case 0:
label.font = [[PTVConfig instance] normalFont:fontSize];
break;
case 1:
label.font = [[PTVConfig instance] boldFont:fontSize];
break;
default:
label.font = [[PTVConfig instance] italicFont:fontSize];
break;
}
CGRect bound = [label textRectForBounds:CGRectMake(0, 0, MAXFLOAT, fontSize * 1.5) limitedToNumberOfLines:1];
CGFloat width = bound.size.width;
return width;
}
获取 label 的宽度
@param fontType 0:正常 1:粗体 2:斜体
*/
- (CGFloat)getLabelWidth:(NSString *)text fontSize:(CGFloat)fontSize type:(NSInteger)fontType
{
UILabel *label = [[UILabel alloc] init];
label.text = text;
switch (fontType)
{
case 0:
label.font = [[PTVConfig instance] normalFont:fontSize];
break;
case 1:
label.font = [[PTVConfig instance] boldFont:fontSize];
break;
default:
label.font = [[PTVConfig instance] italicFont:fontSize];
break;
}
CGRect bound = [label textRectForBounds:CGRectMake(0, 0, MAXFLOAT, fontSize * 1.5) limitedToNumberOfLines:1];
CGFloat width = bound.size.width;
return width;
}
相关文章推荐
- UISlider
- UIScrollView UICollectionView 无法响应touch事件
- UIKit,UIView
- 动态绑定事件插件—livequery
- 1.大道至简的数据处理工具(Power Query)
- requirejs的简单使用
- ui2
- UI
- 128. Longest Consecutive Sequence
- UIImage图片处理(更改颜色,修改透明度,缩小,合并图片)
- EasyUI 之 dataGrid前台状态值转换
- 1099. Build A Binary Search Tree (30)
- MGSwipeTableCell的使用(UItabelCell 滑动拉出多个按钮)
- iOS UITableView
- iOS UI基础1
- 阿里巴巴-德鲁伊druid连接池配置
- STL---deque---学习
- aapt.exe'' finished with non-zero exit value -1073741819
- hdu_3804_Query on a tree(树链剖分)
- hdu_3804_Query on a tree(树链剖分)