【发布时间】:2015-04-21 10:50:13
【问题描述】:
如果是 TextView 我可以做
self.textView.textContainer.lineFragmentPadding = 0;
但我拥有的是多行标签。如何删除填充?
【问题讨论】:
标签: ios iphone uilabel padding
如果是 TextView 我可以做
self.textView.textContainer.lineFragmentPadding = 0;
但我拥有的是多行标签。如何删除填充?
【问题讨论】:
标签: ios iphone uilabel padding
你可以试试这个:
let attributedString: NSMutableAttributedString = NSMutableAttributedString(string: str)
let paragraphStyle: NSMutableParagraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineHeightMultiple = 0.75 //or other values you like
attributedString.addAttribute(NSAttributedString.Key.paragraphStyle, value: paragraphStyle, range: NSMakeRange(0, str.count))
typeLabel.attributedText = attributedString
【讨论】:
我建议将你的 UILabel 更改为 UITextView 并放入此代码。
yourTextView.textContainerInset = UIEdgeInsetsMake(0,0,0,0);
别忘了设置你的TextView
yourTextView.editable = NO
yourTextView.scrollEnabled = NO
【讨论】:
如果您使用的是 iOS 8,请尝试更改 layoutMargins 属性的 insets 值。如果它不起作用或者您针对的是早期版本,请查看this answer.
【讨论】:
NSMutableParagraphStyle 有一个名为 lineSpacing 的属性。尝试将此属性添加到属性字符串并设置标签的属性文本
【讨论】: