I want to display attributed text label inside a scrollview. I use the following code the label displays the text in centre and some extra white space is added in top and bottom.
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];
The below is my output