简体   繁体   English

UIButton自定义字体未显示

[英]UIButton Custom Font not showing

I've checked out the other similar questions and done what's listed in those, I think, but my custom font is still not showing on a UI button. 我认为我已经检查了其他类似的问题,并完成了其中列出的内容,但是我的自定义字体仍未显示在UI按钮上。

The font is in the project, and it is appearing correctly in my UITableViewCells, so I know the font works fine. 该字体在项目中,并且可以正确显示在我的UITableViewCells中,因此我知道该字体可以正常工作。

I'm loading the view, and assigning the font to the button, but when I run the app it's not showing up the correct font. 我正在加载视图,并将字体分配给按钮,但是当我运行应用程序时,它没有显示正确的字体。

FirstViewController.h FirstViewController.h

@interface FirstViewController : UIViewController <UITextFieldDelegate, UITableViewDelegate, UITableViewDataSource> {
    ...    
    UIButton *searchButton;
    ...
}

...
@property (nonatomic, retain) IBOutlet UIButton *searchButton;
...

@end

Then I've got this in FirstViewController.m 然后我在FirstViewController.m中得到了这个

@synthesize searchButton;

- (void)viewDidLoad
{
    [super viewDidLoad];    

    self.searchButton.titleLabel.font = [UIFont fontWithName: @"FontFile" size: 11.0 ];
}

What have I done wrong? 我做错了什么?

[self.searchButton setTitle:@"ButtonTitle" forState:UIControlStateNormal];

As jamihash pointed out, I hadn't hooked up the button from IB to the code. 正如jamihash所指出的那样,我没有将按钮从IB连接到代码。 Doing that fixed it. 这样做解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM