我試圖在按鈕上設置標題的字體。我從蘋果文檔中讀取Objective C中的字體並嘗試實現,但不改變字體。我也試過這個帖子... setting UIButton font。我得到了我的字體從谷歌的字體......「Nunito-Black.tff」如何在按鈕的標題上設置字體Objective-C
這裏是我下面的代碼,
- (void)addHeaderButton {
_headerButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.headerButton.frame = self.bounds;
self.headerButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[self.headerButton setTitleColor:[UIColor colorWithRed:(0.0/255.0) green:(51.0/255.0) blue:(102.0/255.0) alpha:(1.0)] forState:UIControlStateNormal];
self.headerButton.titleLabel.font = [UIFont fontWithName:@"Nunito-Black" size:25];
//[self.headerButton setFont:[UIFont systemFontOfSize:25]];
[self.headerButton addTarget:self action:@selector(headerButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:self.headerButton];
}
是否字體名稱設爲您的尊敬的元素之後獲取字體的名稱它至少用於「UILabel」?是'[UIFont fontWithName:@「Nunito-Black」size:25];'nil? – Larme
您是否已將字體添加到項目中?閱讀[這裏和其他常見錯誤](http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/)。另外,請參閱[包含的字體]列表(http://iosfonts.com/)。 – albertamg
@albertamg是的,我做過 –