I am working with custom fonts and I have a bit of a snag.
Some of the fonts work just fine with sizeToFit like this:

However, other custom fonts are getting cut off on the left and bottom as this one is:

I could 'hack' it and just check for every font type and add a few pixels but I'd like to know if there is a cleaner solution or even an explanation as to why this is happening.
Thanks!
Here is my custom UILabel font setting code
func setNewFont(fontName:String,size:CGFloat)
    {
        self.font = UIFont(name: fontName, size: size)
        sizeToFit()
    }
This post explained how to fix the vertical problem:
http://www.andyyardley.com/2012/04/24/custom-ios-fonts-and-how-to-fix-the-vertical-position-problem/
However the left side of the font was still getting cut off.
So in addition to the fix above, I also overrode the draw call and offset the x value (adjust the minLeftBearing in the xml file did NOT fix anything, clearly xcode ignores it).
 override func drawTextInRect(rect: CGRect)
    {
        if(font.fontName == "JennaSue")//JennaSue
        {
            var newBounds:CGRect = CGRectMake(rect.origin.x+2,rect.origin.y,rect.width,rect.height)
            super.drawTextInRect(newBounds)
        }else
        {
            super.drawTextInRect(rect)
        }
    }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With