[英]As of iOS 10.3: UIButton ignoring negative paragraph lineSpacing in NSAttributedString
我有一個UIButton,它實際上只是2個單詞,包裝成2行(稍后我在代碼中將lines的值設置為“ 2”)。 我一直在通過為段lineSpacing輸入一個負值來加強默認的lineSpacing(簡化並顯示如下)。
從iOS 10.3開始,看來負值已被忽略。 雖然我可以將lineSpacing增加為正值,但我無法再收緊這兩行。
有誰知道如何在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 10.2中的代碼更改行空間
NSMutableParagraphStyle *paraStyle = [NSMutableParagraphStyle defaultParagraphStyle].mutableCopy;
paraStyle.alignment = NSTextAlignmentCenter;
paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
paraStyle.paragraphSpacing = -8;
[self setAttributedTitle:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"test button\n normal", titleString] attributes:@{NSParagraphStyleAttributeName:paraStyle}] forState:UIControlStateNormal];
[self setAttributedTitle:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"test button\n selected", titleString] attributes:@{NSParagraphStyleAttributeName:paraStyle}] forState:UIControlStateSelected];
我想也許您可以更改段落間距,它可以工作〜
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.