开发者

Has anyone tried integrating custom fonts in UIButton?

Trying to put in FontLabel (http://github.com/zynga/FontLabel) into a UIButton. At first I wanted to set titlelabel. But it's restricting a setter to it so i can't just set the label to it.

Just wonderin开发者_开发知识库g if anyone has an idea in doing this without using images to set my custom button.


You could extend the UILabel class through a category to add some functionality. The problem is that UIButton creates its own UILabel, and you can't override that (safely). So if you choose to use a UIButton, your only option for changing the label's behavior from that of a standard UILabel is to actually change the UILabel class (via categories).

Alternatively, you could write your own UIControl and mimic the functionality of UIButton. Then you can do whatever you want.

EDIT - If that FontLabel class extends from UILabel, it may be possible to extend UIButton and use method swizzling to force it to instantiate a FontLabel as its titleLabel. This is pretty extreme though, and I think you're much better off writing your own UIControl that mimics button behavior.


This is a bit old but you can just import the font files (.ttf) in your project and call them with:

-[UIFont fontWithName:size:]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜