Custom Font on Uibutton Title Clipped on Top of Word

custom font on UIbutton title clipped on top of word

I had a similar problem, where a diaeresis got cut off on top of the titlelabel.
I made a UIButton subclass and used this code to fix the problem:

-(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;
}

Cropped UIButton Title

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.

Custom font not showing diaeresis in capital letters

I solved this problem by following this answer on the question shared by Bob
https://stackoverflow.com/a/8314197/617787

The only thing to be aware of this solution (changing the "ascender" of the font file) is that the space between lines on multiline UILabels using this modified font will change as well, so you might use NSAttributedString to modify it in a per case basis.

Changing UILabel title in custom UIButton without positional change

You can do it in many way but the simplest way :

Take a UIView and then others two-element (a label a imageView) set in this View and make it look like button then set constraint as you want. Then addTarget to label and do all functionality to that that target selector method.



Related Topics



Leave a reply



Submit