Sandeep Kumar Gupta
Sandeep Kumar Gupta

Reputation: 129

How to make Text Shadow in ios

How to make shadow of @"Hello World !" in below code?

Thanks in advance !!

UILabel *lbl = [[UILabel alloc]init];
lbl.frame = CGRectMake(0,0,150,50);
lbl.text = @"Hello World!";

Upvotes: 4

Views: 3853

Answers (4)

Johnny Rockex
Johnny Rockex

Reputation: 4196

testLabel.shadowColor = [UIColor blackColor];
testLabel.shadowOffset = CGSizeMake(0.0, -0.5);

Upvotes: 0

Leo
Leo

Reputation: 24714

Use attributedString

enter image description here

Code

 UILabel * Label = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 200, 60)];
[self.view addSubview:Label];
NSMutableAttributedString * mutableAttriStr = [[NSMutableAttributedString alloc] initWithString:@"Wenchen"];
NSShadow * shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor blueColor];
shadow.shadowBlurRadius = 2.0;
shadow.shadowOffset = CGSizeMake(1.0, 1.0);
NSDictionary * attris = @{NSShadowAttributeName:shadow};
[mutableAttriStr setAttributes:attris range:NSMakeRange(0,mutableAttriStr.length)];
Label.attributedText = mutableAttriStr;

Upvotes: 8

iAnurag
iAnurag

Reputation: 9356

UILabel *label = [[UILabel alloc]init];
label.frame = CGRectMake(0,0,150,50);
label.text = @"Hello World!";
label.layer.shadowColor = [label.textColor CGColor];
label.layer.shadowOffset = CGSizeMake(0.0, 0.0);

Import and play with some parameters:

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

Upvotes: 1

iPeta
iPeta

Reputation: 832

UILabel *lbl = [[UILabel alloc]init];
lbl.frame = CGRectMake(0,0,150,50);
lbl.text = @"Hello World!";
lbl.layer.shadowOpacity = 0.8;
lbl.layer.shadowColor = [UIColor blackColor].CGColor;
lbl.layer.shadowOffset = CGSizeMake(0.5, 1.0);

Upvotes: 4

Related Questions