0
我想在滚动视图中显示属性文本标签。我使用以下代码标签显示中间的文本,并在顶部和底部添加一些额外的空白区域。下面UILabel在长文本的顶部和底部显示更多空白区域
NSString *STR_titl_iten_des = @"Item Description";
NSString *STR_descrip_detail = @"Long text to be displayed";
self.lbl_item_descrip.numberOfLines = 0;
NSString *text2 = [NSString stringWithFormat:@"%@\n%@",STR_titl_iten_des,STR_descrip_detail];
if ([self.lbl_item_descrip respondsToSelector:@selector(setAttributedText:)]) {
NSDictionary *attribs = @{
NSForegroundColorAttributeName: self.lbl_item_descrip.textColor,
NSFontAttributeName: self.lbl_item_descrip.font
};
NSMutableAttributedString *attributedText =
[[NSMutableAttributedString alloc] initWithString:text2
attributes:attribs];
NSRange cmp = [text2 rangeOfString:STR_titl_iten_des];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
[attributedText setAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-Bold" size:21.0]}
range:cmp];
}
else
{
[attributedText setAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-Bold" size:17.0]}
range:cmp];
}
self.lbl_item_descrip.attributedText = attributedText;
}
else
{
self.lbl_item_descrip.text = text;
}
[_lbl_item_descrip sizeToFit];
是我的输出
你在使用autolayout吗? – Venkat
不,我没有使用自动布局。这只是一个细节页面,所以没有使用自动布局 –
我试图使用覆盖UILabel也不工作 –