如何在iOS 7下制作UISwitch而不采用背后视图的背景颜色? [英] How do I make a UISwitch under iOS 7 not take the background colour of the view behind it?

查看:139
本文介绍了如何在iOS 7下制作UISwitch而不采用背后视图的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当关闭时看起来像这样:

It looks like this whenever off:

虽然我更喜欢灰色背景。我真的必须使用UIImageView吗?

While I'd prefer more of a grey background. Do I really have to use a UIImageView?

推荐答案

以下是我改变iOS7 UISwitch填充颜色的方法。

Here is how I changed the fill color of my iOS7 UISwitch.

首先你需要导入QuartzCore。

First you need to import QuartzCore.

#import <QuartzCore/QuartzCore.h>

然后设置背景颜色并绕过UISwitch的角落。

Then set the background color and round the UISwitch's corners.

UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(0.0, 0.0, 51.0, 31.0)];
mySwitch.backgroundColor = [UIColor redColor];
mySwitch.layer.cornerRadius = 16.0; // you must import QuartzCore to do this.
[self addSubview:mySwitch];

这将为您提供具有自定义关闭(背景)颜色的UISwitch。

This will give you a UISwitch with a custom off (background) color.

希望这有助于某人:)

这篇关于如何在iOS 7下制作UISwitch而不采用背后视图的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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