UIButton圆角矩形不需要的3D效果 [英] UIButton Rounded Rect unwanted 3D effect

查看:51
本文介绍了UIButton圆角矩形不需要的3D效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在RoundedRect类型的笔尖上有几个UIButtons,在iOS 6之前看起来不错而平坦.在iOS 6中,尽管他们获得了3D效果边框,但我无法摆脱(我提供了图片,但我的声誉太微不足道了).有人可以建议如何使漂亮的平板回头看吗?

I had a couple of UIButtons on a nib of type RoundedRect which before iOS 6 looked nice and flat. In iOS 6 though they've acquired a 3D effect border which I cannot get rid of (I'd supply a pic but my reputation is too puny). Can anybody suggest how to get the nice flat look back?

我敢肯定,这将成为我问过的最愚蠢的问题,答案将是如此简单,以至于我会踢自己一个星期.但是我找不到它,任何帮助将不胜感激.

I'm sure this will turn out to be the stupidest question I've ever asked and that the answer will be so simple I'll kick myself for a week. But I can't find it and any help would be much appreciated.

推荐答案

我不知道为什么会出现这种效果,但是一种解决方法是避免Rounded Rect. 我总是使用自定义按钮.您可以根据需要以任何方式在代码中自定义它们.

I don't know why that effect appeared , but one way to do this is to avoid Rounded Rect. I always use custom buttons. You can customize them in code in any way you want .

例如:

button.layer.cornerRadius = 8;  //this gives it rounded corners
button.layer.borderColor = [[UIColor redColor] CGColor] ; // this is how you set a border
button.layer.borderWidth = 2; //this is how you set the width of the border

UIButton的图层成员是CALayer,您可以为其设置阴影. 是一个很好的教程.

The layer member of the UIButton is a CALayer and you can set shadows to it . This is a good tutorial.

您还可以添加渐变背景,以使按钮更美观,如下所示:

You can also add a gradient background in order to make the button nicer , like this:

CAGradientLayer *layer = [CAGradientLayer layer];

layer.colors = [NSArray arrayWithObjects:
                (id)[[UIColor colorWithRed:skinRed green:skinGreen blue:skinBlue alpha:0.9] CGColor],
                (id)[[UIColor colorWithRed:skinRed green:skinGreen blue:skinBlue alpha:0.8] CGColor],
                (id)[[UIColor colorWithRed:skinRed green:skinGreen blue:skinBlue alpha:0.7] CGColor],
                (id)[[UIColor colorWithRed:skinRed green:skinGreen blue:skinBlue alpha:0.6] CGColor],
                (id)[[UIColor colorWithRed:skinRed green:skinGreen blue:skinBlue alpha:0.5] CGColor],
                (id)[[UIColor colorWithRed:skinRed green:skinGreen blue:skinBlue alpha:0.4] CGColor],
                (id)[[UIColor colorWithRed:skinRed green:skinGreen blue:skinBlue alpha:0.3] CGColor],
                (id)[[UIColor colorWithRed:skinRed green:skinGreen blue:skinBlue alpha:0.2] CGColor],
                (id)[[UIColor colorWithRed:skinRed green:skinGreen blue:skinBlue alpha:0.1] CGColor],
                (id)[[UIColor colorWithRed:skinRed green:skinGreen blue:skinBlue alpha:0.0] CGColor],
                nil];

layer.locations = [NSArray arrayWithObjects:
                   [NSNumber numberWithFloat:0.1],
                   [NSNumber numberWithFloat:0.2],
                   [NSNumber numberWithFloat:0.3],
                   [NSNumber numberWithFloat:0.4],
                   [NSNumber numberWithFloat:0.5],
                   [NSNumber numberWithFloat:0.6],
                   [NSNumber numberWithFloat:0.7],
                   [NSNumber numberWithFloat:0.8],
                   [NSNumber numberWithFloat:0.9],
                   [NSNumber numberWithFloat:1.0],
                   nil];

layer.startPoint        = CGPointMake(0, 0);
layer.frame             = button.layer.bounds;

layer.endPoint          = CGPointMake(0, 1);
layer.contentsGravity   = kCAGravityResize;
[button.layer insertSublayer:layer below:button.titleLabel.layer];

button.layer.masksToBounds = TRUE;

如您所见,一个不错的选择是拥有一些定义应用程序皮肤RGB的全局int var.这样,您可以在几秒钟内对其进行修改.

As you can see , a nice touch would be to have some global int vars that define the RGB of the app's skin. This way you can modify it in seconds.

因此,通过这种方式,您不会受到Apple对SDK版本所做的更改的影响. 而且,您可以按照自己想要的任何方式对其进行自定义,从而获得比IB更高的成就.

So , by using this way you are imune to the changes that Apple makes over SDK versions. And you can customize it in any way that you want , achieving much more than you could ever get in IB.

希望这会有所帮助.

干杯!

这篇关于UIButton圆角矩形不需要的3D效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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