2017-08-28 7 views
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]; 

以下は、私の出力

enter image description hereenter image description here

+0

あなたはautolayoutを使用していますか? – Venkat

+0

いいえ私は自動レイアウトを使用していません。これはちょうど詳細なページなので、自動レイアウトは使用しません –

+0

私はUILabelを無効にしようとしましたが、うまく動作しません。 –

答えて

-1

それは一度試してください後、あなたが[_lbl_item_descrip sizeToFit];を削除できます。

+0

複数の行が表示されない –

関連する問題