Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!";
like image 578
Sandeep Kumar Gupta Avatar asked Dec 10 '22 22:12

Sandeep Kumar Gupta


1 Answers

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;
like image 99
Leo Avatar answered Dec 30 '22 23:12

Leo