gpt4 book ai didi

ios - 如何在ios中制作文字阴影

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:01:13 25 4
gpt4 key购买 nike

如何制作@"Hello World!"的影子在下面的代码中?

提前致谢!!

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

最佳答案

使用attributedString

enter image description here

代码

 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;

关于ios - 如何在ios中制作文字阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31311238/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com