If code of FontAwesome
Icon is ""
, then set text to @"U0000f007"
into Title.
Use Following code For UIButton:-
myBtn.titleLabel.font =[UIFont fontWithName:@"FontAwesome" size:20.0];
[myBtn setTitle:@"U0000f007" forState:UIControlStateNormal]];
Use Following code For UIBarButton:-
[self.barButton setTitleTextAttributes:@{
NSFontAttributeName: [UIFont fontWithName:@"FontAwesome" size:24.0],
NSForegroundColorAttributeName: self.view.tintColor
} forState:UIControlStateNormal];
[self.barButton setTitle:@"U0000f007"]];
If you want to append your string with icon then use following code:-
NSString * myString = @"U0000f007 Change";
NSMutableAttributedString *astring = [[NSMutableAttributedString alloc] initWithString:myString];
[astring addAttribute:NSFontAttributeName
value:[UIFont fontWithName:@"FontAwesome" size:22.0]
range:NSMakeRange(0,1)]; //If Icon is on starting position
[myBtn setAttributedTitle:astring forState:UIControlStateNormal];
Hope, this is what you're looking for. Any concern get back to me. :)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…