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 of button text cut off when using Font Awesome #3

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

Bottom of button text cut off when using Font Awesome #3

squeeish opened this issue Dec 23, 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 by Vaberer's Font-Awesome-Swift library.

Imgur

Do you have any hints to what might be causing this problem?

@ldiqual
Copy link
Contributor

ldiqual commented Dec 23, 2015

@squeeish Looks like a titleEdgeInsets issue to me. SwiftyButton plays with title insets internally so I'm not too surprised.

Would you mind sharing a code example so I can investigate further? Thank you!

@squeeish
Copy link
Author

@ldiqual thanks! It's pretty simple:

https://github.com/Vaberer/Font-Awesome-Swift adds functions to UIButton, which I'm using as follows:

buttonLogin.setFAText(prefixText: "Log in ", icon: FAType.FALock, 
    postfixText: "", size: 14, forState: .Normal)

I took a look at Font-Awesome-Swift's library, this is the code of .setFAText. I'm not sure how to investigate further from here.

func setFAText(prefixText prefixText: String, icon: FAType?, postfixText: String, size: CGFloat?, forState state: UIControlState, iconSize: CGFloat? = nil) {

        if let titleLabel = titleLabel {

            FontLoader.loadFontIfNeeded()
            let textFont = UIFont(name: FAStruct.FontName, size: size ?? titleLabel.font.pointSize)
            assert(textFont != nil, FAStruct.ErrorAnnounce)
            titleLabel.font = textFont!

            let textAttribute = [NSFontAttributeName : titleLabel.font]
            let myString = NSMutableAttributedString(string: prefixText, attributes: textAttribute )

            if let iconText = icon?.text {

                let iconFont = UIFont(name: FAStruct.FontName, size: iconSize ?? size ?? titleLabel.font.pointSize)!
                let iconAttribute = [NSFontAttributeName : iconFont]

                let iconString = NSAttributedString(string: iconText, attributes: iconAttribute)
                myString.appendAttributedString(iconString)
            }

            let postfixString = NSAttributedString(string: postfixText)
            myString.appendAttributedString(postfixString)

            setAttributedTitle(myString, forState: state)
        }
    }

@ldiqual
Copy link
Contributor

ldiqual commented Jan 5, 2016

@squeeish I played a bit with your code and the library you linked to, and it turns out that using a regular UIButton causes the same issue:

image

So this bug is unrelated to SwiftyButton. From what I saw, it only happens when using the FA font, not when using the system font, so there's something wrong there (probably the line height). I'd suggest that you open an issue on the library's issue tracker.

Let me know if you need anything else! Closing this.

@ldiqual ldiqual closed this as completed Jan 5, 2016
@squeeish
Copy link
Author

squeeish commented Jan 6, 2016

I will. Thanks for taking the time to help me out!

@squeeish
Copy link
Author

squeeish commented Oct 2, 2016

For anyone else who needs a solution to this, see Vaberer/Font-Awesome-Swift#20

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

2 participants