gpt4 book ai didi

ios - UIButton 阴影图层效果

转载 作者:可可西里 更新时间:2023-11-01 03:39:42 27 4
gpt4 key购买 nike

我正在创建一个类似于此图像的 UIButton: enter image description here

我用下面的代码试了一下:

+(void)createShadowOnView:(UIView *)view color:(UIColor *)color width:(CGFloat)width height:(CGFloat)height shadowOpacity:(CGFloat)shadowOpacity andShadowRadius:(CGFloat)radius{

view.layer.masksToBounds = NO;
view.layer.shadowColor = color.CGColor;
view.layer.shadowOffset = CGSizeMake(width,height);
view.layer.shadowOpacity = shadowOpacity;
[view.layer setShadowRadius:radius];
}

我能够做到这一点:

enter image description here

我希望 Button 上的阴影效果只保留在底部。

我怎样才能达到预期的效果。

最佳答案

也许你应该设置view的backgroundcolor,这样标题就没有阴影了,你可以设置view.layer.shadowOffset来改变阴影的大小。

UIButton *customBTn = [UIButton buttonWithType:UIButtonTypeCustom];
customBTn.backgroundColor = [UIColor whiteColor];
customBTn.frame = CGRectMake(100, 100, 200, 50);
[customBTn setTitle:@"Sign Up" forState:UIControlStateNormal];
[customBTn setTitleColor:[UIColor colorWithRed:1/255.0 green:168/255.0 blue:244/255.0 alpha:1.0] forState:UIControlStateNormal];
customBTn.layer.borderColor = [UIColor colorWithRed:1/255.0 green:168/255.0 blue:244/255.0 alpha:1.0].CGColor;
customBTn.layer.borderWidth = 2;
customBTn.layer.cornerRadius = 25;
customBTn.layer.shadowColor = [UIColor lightGrayColor].CGColor;
customBTn.layer.shadowOffset = CGSizeMake(0,8);
customBTn.layer.shadowOpacity = 0.9;
[self.view addSubview:customBTn];

输出:-

enter image description here

关于ios - UIButton 阴影图层效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35737655/

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