0

I'm trying to use AwesomeFont in my iOS app, but I'm not having any luck. I declared some UIBarButtonItem's and then wanted to set AwesomeFont icons to them. But Xcode keeps throwing errors.

This is the code:

#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

I keep getting Property 'font' not found on object of type 'UIBarButtonItem *' andProperty 'text' not found on object of type 'UIBarButtonItem *'`. What am I doing wrong?

user4191537
  • 203
  • 2
  • 14

2 Answers2

2

The error shows because UIBarButtonItem don't have the property of font and text.

Instead, You can use 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];
}
Zigii Wong
  • 7,766
  • 8
  • 51
  • 79
0

Posting again the same solution from here:

[self.barButton setTitleTextAttributes:@{
              NSFontAttributeName: [UIFont fontWithName:@"FontAwesome" size:24.0]
                                     } forState:UIControlStateNormal]; 
[self.barButton setTitle:[NSString fontAwesomeIconStringForIconIdentifier:@"fa-camera"]];
Community
  • 1
  • 1
user623396
  • 1,537
  • 1
  • 17
  • 39