創建一個button設置背景圖片,然後加一個label在button上,設置label的text的字體大小,不起作用,請問怎麼修改?代碼如下
returnButton = [UIButton buttonWithType:UIButtonTypeCustom];
returnButton.frame = CGRectMake(10, 9, 50, 28);
[returnButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
[returnButton setImage:[UIImage imageNamed:@"US MEAT_buttons.png"] forState:UIControlStateNormal];
[returnButton setImage:[UIImage imageNamed:@""] forState:UIControlStateHighlighted];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(8, 2, 50, 20)];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor whiteColor];
label.font = [UIFont fontWithName:@"STHeiti-Medium.ttc" size:10];
label.text = @"返回";
[returnButton addSubview:label];
[label release];
可能是你的自定義字體沒設置好
解決步驟:
1.添加字體文件到源文件中
2.編輯info.plist:添加一條新條目 Fonts provided by application.
3.在每個文件中,加入文件名到這個數組中
label.font = [UIFont fontWithName:@"STHeiti-Medium" size:10];
比如我添加字體 DejaVu Sans Mono