gpt4 book ai didi

iphone - 我的按钮上有阴影

转载 作者:可可西里 更新时间:2023-11-01 03:38:54 24 4
gpt4 key购买 nike

我正在为 iPad 应用程序以编程方式创建按钮。当我看到按钮时,它下面似乎有一个阴影类型的东西。它是什么,我该如何摆脱它?

shadow button

这是创建它的代码:

UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.titleLabel.font = [UIFont fontWithName:@"Trebuchet MS" size:12];
[myButton setTitle:@"test" forState:UIControlStateNormal];
myButton.frame = CGRectMake(0, 0, self.leftScrollView.frame.size.width, 50);

UIImageView *myImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gear12.png"]];

[myButton addSubview:myImageView];
[self.leftScrollView addSubview:myButton];

更新:

好的,我注意到我只有在我的 ScrollView 中才能看到这种效果。如果我将它添加到 View 中,则没有阴影效果。

最上面的测试按钮,按钮是 View 的 subview 。底部按钮是 ScrollView 的 subview , ScrollView 是 View 的 subview (按钮/ View 与按钮/ ScrollView / View )。

白色部分是 View ,灰色部分是 ScrollView / View 。

shadow effect 2

更新 2:

正如 robmayor 所指出的,UIButton 始终具有双线效果,只是在背景颜色为白色时不明显。蓝色是 View ,灰色是 subview ScrollView 。

enter image description here

最佳答案

这个问题很旧(6 个月),但我找到了一个解决方案来删除/掩盖双线的这种不良影响。

[yourButton.layer setBackgroundColor: [[UIColor blackColor]CGColor]];
[yourButton.layer setBorderWidth:1.0f];
[yourButton.layer setBorderColor:[[UIColor blackColor]CGColor]];
[yourButton.layer setShadowOpacity:0.1f];
[yourButton.layer setCornerRadius:10];

选择的 UIColor 取决于您 View 的当前背景。

结果:enter image description here

关于iphone - 我的按钮上有阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8316703/

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