Awesome Font在iOS应用程序中不起作用

时间:2014-11-28 15:09:11

标签: ios objective-c xcode

我正在尝试在我的iOS应用中使用AwesomeFont,但我没有运气。我声明了一些UIBarButtonItem,然后想要为它们设置AwesomeFont图标。但Xcode不断抛出错误。

这是代码:

#import "MainController.h"
#import "NSString+FontAwesome.h"

@interface MainController ()

@property (weak, nonatomic) IBOutlet UIBarButtonItem *movies;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *shows;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *episodes;

@end

@implementation MainController

- (void)viewDidLoad
{
    [super viewDidLoad];
    id dotCircleO  = [NSString fontAwesomeIconStringForEnum:FADotCircleO];
    self.movies.font = [UIFont fontWithName:kFontAwesomeFamilyName size:32.f];
    self.movies.text = [NSString stringWithFormat:@"%@", dotCircleO];
}

@end

我一直在'UIBarButtonItem *'类型的对象上找不到Property 'font' not found on object of type 'UIBarButtonItem *' and属性'文本'。我做错了什么?

2 个答案:

答案 0 :(得分:2)

错误显示是因为UIBarButtonItem没有fonttext的属性。

相反,您可以使用UIButton

@property (weak, nonatomic) IBOutlet UIButton *movies;
@property (weak, nonatomic) IBOutlet UIButton *shows;
@property (weak, nonatomic) IBOutlet UIButton *episodes;

- (void)viewDidLoad
{
   [super viewDidLoad];
   id dotCircleO  = [NSString fontAwesomeIconStringForEnum:FADotCircleO];
   self.movies.titleLabel.font = [UIFont fontWithName:kFontAwesomeFamilyName size:32.f];
   self.movies.titleLabel.text = [NSString stringWithFormat:@"%@", dotCircleO];
}

答案 1 :(得分:0)

再次从here发布相同的解决方案:

[self.barButton setTitleTextAttributes:@{
              NSFontAttributeName: [UIFont fontWithName:@"FontAwesome" size:24.0]
                                     } forState:UIControlStateNormal]; 
[self.barButton setTitle:[NSString fontAwesomeIconStringForIconIdentifier:@"fa-camera"]];