Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bottom part of text cut off #20

Closed
squeeish opened this issue Dec 18, 2015 · 5 comments
Closed

Bottom part of text cut off #20

squeeish opened this issue Dec 18, 2015 · 5 comments

Comments

@squeeish
Copy link

I'm new to iOS programming. I've noticed that if I have a prefix containing the letters "g", "p", etc, the bottom part of the text is cut off when I use font awesome icons.

Imgur

Is there a workaround to that? That's Swiftybutton by the way.

@wherewelive
Copy link

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

@RanjitKadam
Copy link

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

@wherewelive
Copy link

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

@Vaberer
Copy link
Owner

Vaberer commented Mar 22, 2016

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

@cschar
Copy link

cschar commented Aug 5, 2018

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")
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants