I am using a custom font for the title of a UIButton. It works, except with this particular font a portion of the first character is clipped. For example:
I tried setting the contentEdgeInsets and titleEdgeInsets and can't seem to get it not clipped. I also tried setting the button.titleLabel.clipsToBounds property to NO;
Any suggestions would be greatly appreciated.
Although Jeshua's solution works fine, it's not an optimal in my eyes.
I'd rather recommend to subclass UIButton and overwrite it's layoutSubviews
Method.
-(void)layoutSubviews
{
[super layoutSubviews];
CGRect frame = self.titleLabel.frame;
frame.size.height = self.bounds.size.height;
frame.origin.y = self.titleEdgeInsets.top;
self.titleLabel.frame = frame;
}
So I just ended up setting the UIButton title to nil and added my own UILabel as a subview to the UIButton. I set the UILabel frame to the same size as the button and set it to be centered.
Not the most elegant solution I am sure, but it gets the job done.
It looks to me like your content is aligned funkily. If the frame of the label is not directly accessible, use [button setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
to try to fix the horizontal alignment issue.
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