UIButton + italic font = clipping

三世轮回 提交于 2019-12-11 23:54:31

问题


The problem is that UIButton clips title tail (for about 1-2 pixels at the end) when I use italic font like Helvetica Oblique with size bigger than 13. Does anybody know a solution for this problem?


回答1:


Subclass UIButton class and override setTitle with:

- (void)setTitle:(NSString *)title forState:(UIControlState)state { [super setTitle:[NSString stringWithFormat:@" %@ ", title] forState:state]; }

This will add additional spaces from both sides of your text. Easy & simple.




回答2:


I had this issue with my script font. Unfortunately there isn't a simple way to fix it. I tried everything and then ended up subclassing UIButton. You can read the details for implementation here: http://blog.tinymission.com/post/subclassing-uibutton

Basically, the easiest thing to do would be to put your own UILabel on top of the UIButton, but for me, that wouldn't work well so I subclassed UIButton.




回答3:


You can set Italic font by setting Uibutton property as

button.titleLabel?.font = UIFont.italicSystemFont(ofSize: 17)



来源:https://stackoverflow.com/questions/6624447/uibutton-italic-font-clipping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!