【发布时间】: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, andthumbTintColor`)。
标签: ios objective-c ios7 uiswitch