我的按钮上有一个阴影 [英] There's a shadow on my button

查看:115
本文介绍了我的按钮上有一个阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为iPad应用程序创建一个程序化按钮。当我看到按钮时,它下面看起来像是一个阴影类型的东西。它是什么以及如何摆脱它?

i'm creating a button programmaticly for an iPad application. when i see the button, there looks to be a shadow type thing below it. what is it and how can i get rid of it?

这是创建它的代码:

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

更新:

好的,我注意到了我只能在我的滚动视图中获得该效果。如果我将它添加到视图,没有阴影效果。

ok, i notice i only get that effect when its in my scrollview. if i add it to the view, no shadow effect.

顶部测试按钮,该按钮是视图的子视图。底部按钮是滚动视图的子视图,它是视图的子视图(按钮/视图与按钮/滚动视图/视图)。

the top test button, the button is a subview of the view. the bottom button is a subview of the scrollview which is a subview of the view (button/view vs button/scrollview/view).

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

white section is the view, grey is the scrollview/view.

更新2:

正如robmayor所指出的,UIButtons总是有双线效果,只是没有注意到当背景颜色为白色时。蓝色是视图,灰色是子视图滚动视图。

as pointed out by robmayor, UIButtons always have that double line effect, just not noticeble when the background color is white. the blue is a view and the grey is the subview scrollview.

推荐答案

在iPad上,圆角矩形UIButton始终沿其底边绘制一条白线。如果按钮的超级视图为白色,则无法看到白线,但它仍然存在。

On iPads, a rounded-rect UIButton always draws a white line along its bottom edge. You can't see that white line if the button's superview is white, but it's still there.

您有以下几种选择:


  • 使superview变白。这是最简单的,但您可能不喜欢它的外观。

  • Make the superview white. This is the easiest but you might not like the way it looks.

在您喜欢的图像编辑器中制作一些圆角矩形图像。将按钮类型设置为自定义并将圆角矩形图像设置为按钮的图像。

Make some rounded rect images in your favorite image editor. Set the button type to custom and set your rounded rect images as the button's images.

创建UIButton的子类并覆盖其 drawRect :方法。

Make a subclass of UIButton and override its drawRect: method.

将按钮类型设置为自定义并使用按钮的图层属性( button.layer .backgroundColor button.layer.borderColor button.layer.borderWidth button.layer.cornerRadius )为按钮提供圆角矩形外观。触摸按钮时,你需要更新 button.layer.backgroundColor ,如果你想让它像普通按钮一样变蓝。 (实际上正常的使用蓝色渐变。)

Set the button type to custom and use the button's layer properties (button.layer.backgroundColor, button.layer.borderColor, button.layer.borderWidth, button.layer.cornerRadius) to give the button a rounded rect appearance. You'll have to update button.layer.backgroundColor when the button is touched if you want it to turn blue like a normal one does. (Actually a normal one uses a blue gradient.)

这篇关于我的按钮上有一个阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆