Closed squeeish closed 8 years ago
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 :)
hey I am also facing the same issue, but this lib, does not contain "fontAwesomeIconWithName"
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
Thank you guys for a hint how to fix it. New version of Font Awesome works great!
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")
}
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.
Is there a workaround to that? That's Swiftybutton by the way.