Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone UILabel text soft shadow

I know soft shadows are not supported by the UILabel out of the box, on the iPhone. So what would be the best way to implement my own one?

EDIT:

Obviously I will subclass the UILabel and draw in the -drawRect: My question is, how do I get the contents of the label as graphics and draw around them, blur them etc...

EDIT 2:

I returned to this question about a year later. In the meantime I've built a class that allows you to easily add soft shadow to a label and tweak it's radius etc and also to draw gradients on the text itself. You can find it on GitHub: https://github.com/doukasd/iOS-Components/tree/master/Views

like image 467
Dimitris Avatar asked Nov 10 '09 16:11

Dimitris


People also ask

How do I add shadows to text messages?

Select the text or WordArt that you want to format. On the Format tab, under Text Styles, click Effects, point to Shadow, and then click the shadow style that you want.

How do I add shadow to text in Swift?

Basic Swift Code for iOS Apps This will not only makes the text attractive but also it will also enhance the user experience. Here we will see how we can add shadow on text. Step 2 − Add label in Main. storyboard and create @IBOutlet of the label and name it lblHelloWorld.

How do I change my UILabel text?

To change the font or the size of a UILabel in a Storyboard or . XIB file, open it in the interface builder. Select the label and then open up the Attribute Inspector (CMD + Option + 5). Select the button on the font box and then you can change your text size or font.


1 Answers

As of 3.2 there is direct support for shadows in the SDK.

label.layer.shadowColor = [label.textColor CGColor]; label.layer.shadowOffset = CGSizeMake(0.0, 0.0); 

#import <QuartzCore/QuartzCore.h> and play with some parameters:

label.layer.shadowRadius = 3.0; label.layer.shadowOpacity = 0.5; 

And, if you find your shadow clipped by the label bounds:

label.layer.masksToBounds = NO; 

finally set

label.layer.shouldRasterize = YES; 
like image 171
IlDan Avatar answered Sep 23 '22 01:09

IlDan