Reputation: 21095
I'm working on a project where UIButtons can have their font color dynamically set depending on user settings. To avoid the issue of a light font on a light background or a dark font on a dark background I'd like to outline my font with a thin, black outline. I'm talking about an outline directly around the letters, not around the label or button itself. Something like the typical LOLcat Impact font outline: http://mintyferret.com/wp-content/uploads/2007/07/lolcat7.gif
Does anyone have an example of this in action? I'm open to suggestions if you have something easier, but I'm not really in a place where I want to create custom images for my buttons. They can have dynamic text and dynamic colors, so I need it to be pretty flexible.
Upvotes: 2
Views: 1998
Reputation: 3431
UIButton contains its title in a UILabel and UILabel has no option to add borders around your characters. The titleLabel property of UIButton is read-only, so you can't replace it with your own UILabel subclass. Therefore, the only option appears to be to draw the text in the button's drawRect function.
Here's a topic on how to draw borders around text: How do I make UILabel display outlined text?
I'm pretty sure you'll have to override the setTitle:forState: and currentTitle functions using your own variables, or the button will draw text behind or in front of the text you draw.
Upvotes: 2