I have a UIButton which is really just 2 words, wrapped to 2 lines (I set the lines value to "2" in code later). I have been tightening up the default lineSpacing by putting in a negative value for the paragraph lineSpacing (as simplified & shown below).
As of iOS 10.3, it appears the negative value is now being ignored. While I can increase the lineSpacing with a positive value, I can not tighten up the 2 lines anymore.
Does anyone else know how to tighten this up in a UIButton? (I'm about ready to change that control up... but thought I'd post the question).
Much thanks all.
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];
edit: Looks like this is also an issue with UILabel also.
i can change the line space using the code in 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];
i guess maybe you can change the paragraphSpacing, it works~
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.