裁剪的UIButton标题 [英] Cropped UIButton Title
问题描述
我使用自定义字体作为UIButton的标题。它有效,除了这个特定的字体,第一个字符的一部分被剪裁。例如:
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:
我尝试设置contentEdgeInsets和titleEdgeInsets,但似乎无法修剪它。我也尝试将button.titleLabel.clipsToBounds属性设置为NO;
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.
推荐答案
所以我最终将UIButton标题设置为nil并将我自己的UILabel作为子视图添加到UIButton。我将UILabel框架设置为与按钮相同的大小并将其设置为居中。
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.
这篇关于裁剪的UIButton标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!