【发布时间】:2017-04-05 17:07:21
【问题描述】:
我有一个 UIButton,它实际上只有 2 个单词,包装为 2 行(我稍后在代码中将行值设置为“2”)。我一直在通过为段落 lineSpacing 输入一个负值来收紧默认 lineSpacing(如下所示)。
从 iOS 10.3 开始,现在似乎忽略了负值。虽然我可以用正值增加 lineSpacing,但我不能再收紧 2 行了。
还有其他人知道如何在 UIButton 中收紧这个吗? (我正准备改变那个控制......但我想我会发布这个问题)。
非常感谢大家。
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = -15.0f;
paragraphStyle.alignment = NSTextAlignmentLeft;
NSDictionary * attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], NSStrokeColorAttributeName,
[UIColor greenColor], NSForegroundColorAttributeName,
@(-2.0), NSStrokeWidthAttributeName,
paragraphStyle, NSParagraphStyleAttributeName,
nil];
NSMutableAttributedString *buttonTitle = [[NSMutableAttributedString alloc] initWithString:str attributes:attributes];
self.theButton.titleLabel.numberOfLines = 2;
[self.theButton setAttributedTitle:buttonTitle forState:UIControlStateNormal];
编辑:看起来这也是 UILabel 的问题。
【问题讨论】:
标签: ios objective-c uibutton nsparagraphstyle ios10.3