Gor*_*ium 14
您可以在界面构建器中执行此操作.此GIF将向您展示如何增加文本的一个部分的大小,并可能更改其字体.
要在代码中执行此操作:
NSString *fullString = @"This bit's plain. This bit's bigger";
NSRange rangeOfPlainBit = [fullString rangeOfString:@"This bit's plain."];
NSRange rangeOfBigBit = [fullString rangeOfString:@"This bit's bigger"];
NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:fullString];
[attributedText setAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"My-font" size:15.0],
NSForegroundColorAttributeName: [UIColor whiteColor]}
range:rangeOfPlainBit];
[attributedText setAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"My-font" size:25.0],
NSForegroundColorAttributeName: [UIColor whiteColor]}
range:rangeOfBigBit];
[self.myButton setAttributedTitle:attributedText forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
SWIFT 3
func customizeButtonFont(fullText: String, mainText: String, creditsText: String, button: UIButton) {
let fontBig = UIFont(name:"SFUIDisplay-Medium", size: 16.0)
let fontSmall = UIFont(name:"SFUIDisplay-Light", size: 14.0)
let attributedString = NSMutableAttributedString(string: fullText, attributes: nil)
let bigRange = (attributedString.string as NSString).range(of: mainText)
let creditsRange = (attributedString.string as NSString).range(of: creditsText)
attributedString.setAttributes([NSAttributedStringKey.font: fontBig, NSAttributedStringKey.foregroundColor: UIColor.white], range: bigRange)
attributedString.setAttributes([NSAttributedStringKey.font: fontSmall, NSAttributedStringKey.foregroundColor: UIColor.white], range: creditsRange)
button.setAttributedTitle(attributedString, for: .normal)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1584 次 |
| 最近记录: |