How to integrate and use Font Awesome with Objective-C or Swift in an Xcode project?

后端 未结 17 1340
不思量自难忘°
不思量自难忘° 2020-12-12 18:07

So I am trying to use this font http://fortawesome.github.com/Font-Awesome/. I\'ve added the font as a resource and put it in the plist file. Here\'s how I am using it:

相关标签:
17条回答
  • 2020-12-12 18:38

    I was looking for the helper library for Swift3 and found this to be very simple and working solution https://github.com/Syndicode/FontAwesomeKitSwift3. It has animations that explain for novices like me how to include it and use quickly.

    0 讨论(0)
  • 2020-12-12 18:43

    In Swift:

    Font Awesome Cheatsheet.

    Tutorial on how to integrate the font called "Font Awesome" in your Xcode project.

    Common Mistakes With Adding Custom Fonts to Your iOS App

    let label = UILabel(frame: CGRectMake(0, 0, 100, 100))
    label.font = UIFont(name: "FontAwesome", size: 40)
    let myChar: UniChar = 0xF180
    label.text = String(format: "%C", myChar)
    self.view.addSubview(label)
    
    0 讨论(0)
  • 2020-12-12 18:47

    BEST solution for FA with XCode:

    1. Copy the icon you want from http://fontawesome.io/cheatsheet/ (I mean mark and copy the icon itself):

    1. Then add a label to your storyboard, and on its properties:

    • RED - Choose FontAwesome as family
    • GREEN - Set the size you want
    • BLUE - Paste here what you copied in the 1st step. (dont worry about the question mark - in the view you should see it properly).

    That's it.

    If you need to change the icon in the code - you can paste 1st step inside your code too:

    0 讨论(0)
  • 2020-12-12 18:48

    Not sure you ever got this working properly, but there's now a couple of nice projects on github:

    https://github.com/alexdrone/ios-fontawesome - which gives you a category for NSString which offers basic help using FontAwesome.

    and https://github.com/leberwurstsaft/FontAwesome-for-iOS which gives you a NSString category with fontAwesomeIconStringForIconIdentifier and also an UIImageView subclass: FAImageView

    0 讨论(0)
  • 2020-12-12 18:49

    You can just use the literal code string by affixing it with \u.

    e.g. You can use \f030 in your iOS app using the following snippet.

    [[[UILabel alloc] initWithFrame:CGRectZero] setText:@"\uf030"];

    0 讨论(0)
  • 2020-12-12 18:49

    not sure if this answer will be useful looking at the date you posted your question.... but to help someone maybe who is doing it at the moment,

    [self.homefeedbutton setTitle:@"o" forState:UIControlStateNormal]; [self.homefeedbutton.titleLabel setFont:[UIFont fontWithName:@"fontawesome" size:30]];

    setTitle:@"o" o is a name of the font, don't use the unichar, instead rename your font to something else preferable a letter, e.g if you check fontello.com , select icon, then click customize code tab, on top of you icon there is a small box, change it to any letter....

    shout if its not clear enough , I will try to explain in a different way.

    0 讨论(0)
提交回复
热议问题