2016-02-27 83 views

回答

8

您可以在Interface Builder做到这一点。这个GIF将告诉你如何增加文本的一个部分的大小,或许改变它的字体。

enter image description here

在代码中做到这一点:

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]; 
+0

感谢队友。没有看到。 –

+0

你能用两条线做这个吗?看起来IB只显示一行... –

+0

如果您使用IB,您应该可以选择您想要的文本并进行更改。你可以选择多行,单独的长段或单独的部分。如果你不能,你可以尝试使用类似于我上面包含的方法的代码,从而获取要更改的文本位。 – Gordonium

-1

只是改变标题的字体大小。

迅速: button.titleLabel.font = UIFont.systemFontOfSize(FONTSIZE)

+0

这将如何帮助在一个uibutton中有两种不同的字体? –

+0

哎呀,我误解了。你需要在同一个按钮上使用NSAttributedString作为不同的字体。 – ravivatish