我的button上有一个阴影

我正在为iPad应用程序编程创build一个button。 当我看到button时,看起来有一个阴影types的东西在它下面。 这是什么,我怎么能摆脱它?

阴影按钮

这是创build它的代码:

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它的效果。 如果我把它添加到视图,没有阴影效果。

顶部的testingbutton,button是视图的子视图。 底部button是scrollview的子视图,它是视图的子视图(button/视图vsbutton/滚动视图/视图)。

白色部分是视图,灰色是滚动视图/视图。

阴影效果2

更新2:

正如robmayor所指出的那样,UIButtons总是具有双重的线条效果,当背景颜色是白色的时候不会显眼。 蓝色是一个视图,灰色是子视图滚动视图。

在这里输入图像说明

在iPad上,一个圆形的UIButton总是在底部边缘绘制一条白线。 如果button的超级视图是白色的,你不能看到白线,但它仍然存在。

你有几个select:

  • 使超级视图变白。 这是最简单的,但你可能不喜欢它的样子。

  • 在你最喜欢的图像编辑器中制作一些圆形的矩形图像。 将buttontypes设置为自定义,并将圆angular矩形图像设置为button的图像。

  • 创build一个UIButton的子类并覆盖它的drawRect:方法。

  • 将buttontypes设置为自定义,并使用button的图层属性( button.layer.backgroundColorbutton.layer.borderColorbutton.layer.borderWidthbutton.layer.cornerRadius )为button指定圆angular矩形外观。 如果你想让它像普通的一样变成蓝色,你必须更新button.layer.backgroundColor 。 (其实正常的使用蓝色渐变。)

这个问题是旧的(6个月),但我find了一个解决scheme,删除/掩盖双线的这种不好的影响。

 [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取决于您的视图的当前背景。

结果: 在这里输入图像说明

[UIButton buttonWithType:UIButtonTypeRoundedRect]replace为:

 UIButton *myButton = [UIButton new]; 

要么:

 UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom]; 

你想要你的自定义button。 如果需要的话,你仍然可以用圆angular做成。