hgpl
hgpl

Reputation: 869

Outline for UILabel text

How do I add a black outline to my white UILabel text?

Upvotes: 10

Views: 15783

Answers (4)

Besi
Besi

Reputation: 22959

One option is to set the shadow, which might not be exactly what you want, but achieves a similar effect. You can manually adjust the offset:

UILabel *myLabel = ...;
lbl.shadowColor = [UIColor whiteColor];
lbl.shadowOffset = CGSizeMake(0, -1.0);

Please note that you can also define this in Interface Builder for your UILabel.

shadow http://i.minus.com/jbiG0jVdOxJbgh.png

If this is not enough for you check out this blog post which deals with subclassing UILabel to get a glow effect:

glow
(source: redrobotstudios.com)

Upvotes: 10

tobihagemann
tobihagemann

Reputation: 601

Disclosure: I'm the developer of THLabel.

I've released a UILabel subclass a while ago, which allows an outline in text and other effects. You can find it here: https://github.com/tobihagemann/THLabel

I'm using Core Text and Core Graphics to achieve the effect.

Upvotes: 6

Nuoji
Nuoji

Reputation: 3448

For iOS5, the usual way is to use CoreGraphics to set fill/stroke and then render the graphics. It can be pretty tricky to get the alignment correct for all font sizes though.

I recommend looking at my solution here. You can either use it straight (it has diffuse shadows as well), or simply pick out the code that does the outline. For iOS6 there is a neater (smaller) solution which works even better. Look here.

Upvotes: 2

Harsh Mehrotra
Harsh Mehrotra

Reputation: 65

I am sure this code will solve your problem.

In KSLabel.m class see this line of code

// Outline color
self.textColor = [UIColor whiteColor];

change it to

self.textColor = [UIColor blackColor];

and you will see the black border of the text.

Upvotes: 1

Related Questions