Last active
June 26, 2020 03:35
-
-
Save fhefh2015/b7afaf7a17ef69bed26f53341d92e6e0 to your computer and use it in GitHub Desktop.
UILabel两端对齐
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSAttributedString *)textAligenJustifiedWith:(NSString *)text lineSpace:(CGFloat)lineSpace { | |
NSMutableAttributedString *mutableAttributedString = [[NSMutableAttributedString alloc] initWithString:text]; | |
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; | |
paragraphStyle.alignment = NSTextAlignmentJustified; | |
paragraphStyle.paragraphSpacing = 11.0; | |
paragraphStyle.paragraphSpacingBefore = 10.0; | |
paragraphStyle.firstLineHeadIndent = 0.0; | |
paragraphStyle.headIndent = 0.0; | |
paragraphStyle.lineSpacing = lineSpace; | |
NSDictionary *dict = @{ | |
NSForegroundColorAttributeName :self.textColor, | |
NSFontAttributeName: self.font, | |
NSParagraphStyleAttributeName: paragraphStyle, | |
NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleNone] | |
}; | |
[mutableAttributedString setAttributes:dict range:NSMakeRange(0, mutableAttributedString.length)]; | |
NSAttributedString *attrString = [mutableAttributedString copy]; | |
return attrString; | |
} | |
- (NSAttributedString *)textAligenJustifiedWith:(NSString *)text { | |
NSMutableAttributedString *mutableAttributedString = [[NSMutableAttributedString alloc] initWithString:text]; | |
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; | |
paragraphStyle.alignment = NSTextAlignmentJustified; | |
paragraphStyle.paragraphSpacing = 11.0; | |
paragraphStyle.paragraphSpacingBefore = 10.0; | |
paragraphStyle.firstLineHeadIndent = 0.0; | |
paragraphStyle.headIndent = 0.0; | |
NSDictionary *dict = @{ | |
NSForegroundColorAttributeName :self.textColor, | |
NSFontAttributeName: self.font, | |
NSParagraphStyleAttributeName: paragraphStyle, | |
NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleNone] | |
}; | |
[mutableAttributedString setAttributes:dict range:NSMakeRange(0, mutableAttributedString.length)]; | |
NSAttributedString *attrString = [mutableAttributedString copy]; | |
return attrString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment