【问题标题】:UISwitch in iOS 7 showing a borderiOS 7 中的 UISwitch 显示边框
【发布时间】:2014-03-27 06:55:09
【问题描述】:

我有一个 UISwitch,它的功能运行良好。我有 2 张大小为 77 x 27 像素的图像,并将它们应用于 ON 和 OFF 图像。

但是,它在 IOS 7 中显示了一个拉伸的边框,如下图所示:

图片显示为拉伸边框,背景颜色为白色

图片显示正常,背景颜色为黑色

我已经尝试了以下代码:

_switcherTheme = [[UISwitch alloc] initWithFrame:switchRect];
_switcherTheme.backgroundColor = [UIColor colorWithRed:36.0/255.0 green:41.0/255.0 blue:45.0/255.0 alpha:1.0];
_switcherTheme.layer.cornerRadius = 16.0;
[_switcherTheme setOnTintColor:[UIColor colorWithRed:223.0/255.0 green:245.0/255.0 blue:241.0/255.0 alpha:1.0]];
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0) {
    [_switcherTheme setOnImage:[UIImage imageNamed:@"color_light.png"]];
    [_switcherTheme setOffImage:[UIImage imageNamed:@"color.png"]];
}

我的问题是:如何使第一张图片的边框正确?

【问题讨论】:

  • UISwitch 不希望使用backgroundColor 或图层的cornerRadius 来操作它的视图。在 iOS 7 中,预计只会修改色调颜色 (tintColor, onTintColor, and thumbTintColor`)。

标签: ios objective-c ios7 uiswitch


【解决方案1】:
【解决方案2】:
UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(0.0, 0.0, 51.0, 31.0)];
mySwitch.backgroundColor = [UIColor greenColor];
mySwitch.layer.cornerRadius = 16.0; // you must import QuartzCore to do this.
[self addSubview:mySwitch];

【讨论】:

    猜你喜欢
    • 2015-10-21
    • 1970-01-01
    • 2022-08-06
    • 1970-01-01
    • 1970-01-01
    • 2010-11-20
    • 2018-06-19
    • 2013-10-30
    • 1970-01-01
    相关资源
    最近更新 更多