Reputation: 4292
I'm a newcomer to text programming in iOS and a bit stumped at the moment. I am creating an example project to learn how to make a lolcat app (start with something fun!).
I have a UIImage with the cat and I'm putting some text on top of it by having a UITextView on top with text.
I'd like to end up with something like this for the text:
I was able to successfully pull this off when I had the text in a UILabel. I used code I found on SO that used drawTextInRect
to accomplish the magic.
Now, I'd like to do the same thing in the UITextView (I want to be able to scroll the text).
**EDIT: ** so here is what I'm trying so far:
var foo = NSAttributedString(string: text, attributes: [
NSStrokeColorAttributeName : UIColor.blackColor(),
NSForegroundColorAttributeName : UIColor.whiteColor(),
NSStrokeWidthAttributeName : NSNumber(float: -4.0),
NSFontAttributeName : UIFont.systemFontOfSize(30.0)
])
That gets me a result like this:
If I now double the stroke width to -8.0 I get the below result which looks pretty darn bad in my estimation. It seems like there is a tradeoff between the stroke width and how much of the fill I can see. Ideally I'd like the stroke to just get wider without eating up the white text.
Upvotes: 3
Views: 5918
Reputation: 21
You can use the help of library DrawingLabel without any CoreGraphics code
DrawingStroke *blackStroke = [DrawingStroke new];
blackStroke.strokeWidth = 3.0;
blackStroke.strokeColor = [UIColor blackColor];
Upvotes: 2
Reputation: 535138
You need to read up on NSAttributedString. You can give letters an outline stroke:
Use the NSStrokeColorAttributeName
and NSStrokeWidthAttributeName
to configure the outline stroke.
Once you have your attributed string you can put it an a label, put it in a text view, or draw it directly, as you please.
Might look a little better if you add some expansion and a tiny bit of shadow:
Upvotes: 3