簡體   English   中英

如何在ios中制作文字陰影

[英]How to make Text Shadow in ios

如何制作@“Hello World!”的影子 在下面的代碼?

提前致謝 !!

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

使用attributedString

在此輸入圖像描述

 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;
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);
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);

進口 並播放一些參數:

label.layer.shadowRadius = 3.0;
label.layer.shadowOpacity = 0.5
label.layer.masksToBounds = NO;
testLabel.shadowColor = [UIColor blackColor];
testLabel.shadowOffset = CGSizeMake(0.0, -0.5);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM