iOS: Append FontAwesome icon with title in UIBarButtonItem and Button

I want a UIBarButton Item like this in my NavigationBar and

enter image description here

  • xcode iOS compare strings
  • How to get the other devices' host name in the same wifi?
  • saving an image to photos library using Swift 2.0
  • How to send silent push to iOS via Google Cloud Messaging
  • How to build and deploy an ios api file in real device using MAC
  • Getting ITMS-4238 “Redundant Binary Upload” error no mater what I change the build version or app version to
  • Normal UIButton like this

    enter image description here

    I already tried using these links
    Question 1 Question 2 Question 3 but didn’t got the output.

    My need is to append that FontAwesome icon with the button title text.

    Can anyone help in this?

    My code is:

    NSString *icon = [NSString fontAwesomeIconStringForIconIdentifier:@"fa-folder-open"];
    
    NSString *locationString = [NSString stringWithFormat:@"%@ %@", icon, @"Change"];
    
    NSMutableAttributedString *astring = [[NSMutableAttributedString alloc] initWithString:locationString];
    
    [astring addAttribute:NSFontAttributeName
                    value:[UIFont iconicFontOfSize:20]
                    range:NSMakeRange(0,1)]; // The first character
    
    changeFolderButton.titleLabel.attributedText = astring;
    

    3 Solutions Collect From Internet About “iOS: Append FontAwesome icon with title in UIBarButtonItem and Button”

    If code of FontAwesome Icon is "&#xf007", 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. 🙂

    In swift 2.0:

        btnAddGroup.titleLabel?.font = UIFont(name:"FontAwesome",size: 50)
        btnAddGroup.setTitle(String.fontAwesomeIconWithCode("fa-plane"), forState: .Normal)
    

    Sorry for late answer but this might help someone in future,Note:Facebook denotes my UIButton

    FAKFontAwesome *Gplus = [FAKFontAwesome googleIconWithSize:20];
        [Gplus addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor]];
        NSMutableAttributedString *twitterMass = [[Gplus attributedString] mutableCopy];
        [twitterMass appendAttributedString:[[NSAttributedString alloc] initWithString:@" Login With Google" attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}]];
        [Facebook setAttributedTitle:twitterMass forState:UIControlStateNormal];