有没有办法在textLabel中使用两种不同字体大小的UIButton?本地?
我不想让UILabel在上面。
答案 0 :(得分:12)
您可以在界面构建器中执行此操作。此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];
答案 1 :(得分:3)
SWIFT 3
class Book {
private int Pages; // Ive tried Changing it to Integer!
private String Author;
private String Title;
public Book() {
}
public Book (String title, String author, int pages){
Author = author;
Title = title;
Pages = pages;
}
public void setauthor(String author){
author = Author;
}
public void settitle(String title){
title = Title;
}
public void setpages(int pages){
pages = Pages;
}
public String getauthor(){
return Author;
}
public String gettitle(){
return Title;
}
public int getpages(){
return Pages;
}
public String printBook(){
if ( Pages == 0 || Pages == null){
return "Title: " + Title + ", "+ "Author: " + Author + ", " + "Pages:" + "1";
}
else{
return "Title: " + Title + ", "+ "Author: " + Author + ", " + "Pages:" + Pages;
}
}
}
答案 2 :(得分:-1)
只需更改标题的字体大小。
迅速: button.titleLabel.font = UIFont.systemFontOfSize(FONTSIZE)