Giter VIP home page Giter VIP logo

Comments (5)

wherewelive avatar wherewelive commented on July 3, 2024

FYI, had the same issue and you can fix it using NSAttributedString and setAttributedTitle for buttons or labels. Here is how to split the icon and text up into an NSAttributedString

let iconPart = NSMutableAttributedString(string: "\(String.fontAwesomeIconWithName(.User))", attributes: [NSFontAttributeName:UIFont.fontAwesomeOfSize(12)])

let textPart = NSMutableAttributedString(string: " whatever your label is here", attributes: [NSFontAttributeName:UIFont.systemFontOfSize(12)])

Then you need to append the textPart to the iconPart (notice the space left in the textPart string)

iconPart.appendAttributedString(textPart)

iconPart is now an NSAttributedString with 2 font types that will not cutoff the text :)

screen shot 2016-02-17 at 2 12 25 pm

from font-awesome-swift.

RanjitKadam avatar RanjitKadam commented on July 3, 2024

hey I am also facing the same issue, but this lib, does not contain "fontAwesomeIconWithName"

from font-awesome-swift.

wherewelive avatar wherewelive commented on July 3, 2024

I was using a different lib (https://github.com/thii/FontAwesome.swift) but idea would be the same here since the icon is just a string

from font-awesome-swift.

Vaberer avatar Vaberer commented on July 3, 2024

Thank you guys for a hint how to fix it. New version of Font Awesome works great!

from font-awesome-swift.

cschar avatar cschar commented on July 3, 2024

If anyones wondering how to get that Attributed String into a BarButton Item (which doesnt accept multi attributed strings....) You can override the customView with a label and set it from there:

     let iconPart = NSMutableAttributedString(string: "\(String.fontAwesomeIcon( name: .videoCamera))", attributes: [NSAttributedStringKey.font:UIFont.fontAwesome(ofSize: 24)])

     let textPart = NSMutableAttributedString(string: "Video", attributes: [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 16)])

     iconPart.append(textPart)
     let label = UILabel()
     label.attributedText = iconPart
     label.sizeToFit()
     label.textColor = self.view.tintColor


     let tap = UITapGestureRecognizer(target: self, action: #selector(MyViewController.tapFunction))
     label.isUserInteractionEnabled = true
     label.addGestureRecognizer(tap)
     MyBarButton.customView = label


//elsewhere in your view Controller:
 @objc
 func tapFunction(sender:UITapGestureRecognizer) {
     print("tap working")
 }

from font-awesome-swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.