[英]How Can I indent only first line of multiline UILabel in iOS?
我想在UILabel的開頭添加一個圖像。 標簽是多行的。 如果我使用contentInset,它會縮進整個標簽,但我只想縮進第一行。
到目前為止我試過這個,這對我不起作用。
UIEdgeInsets titleInsets = UIEdgeInsetsMake(0.0, 40.0, 0.0, 0.0);
valueLabel.contentInset = titleInsets;
它看起來應該是這樣的。
@DavidCaunt的建議對我有用。 我在這里分享代碼。
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
style.firstLineHeadIndent = 50;
[attributedText addAttribute:NSParagraphStyleAttributeName value:style range:range];
[valueLabel setAttributedText:attributedText];
另外,作為user716216指出 - 我們可以使用具有定義的縮進值的選項卡:
NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
paragraphStyle.headIndent = 50;
label.attributedText = [[NSAttributedString alloc] initWithString:
@"\tHow can i add image like this in start of UILabel? Label is multiline.........."
attributes:@{NSParagraphStyleAttributeName: paragraphStyle}];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.