ios - 如何在StoryBoard中为UISwitch设置“打开图像”和“关闭图像”?

标签 ios iphone xcode storyboard uiswitch

我正在UISwitch上工作,我想在Storyboard中为UISwitch设置Image并关闭Image,但未在switch上设置image。

我尝试这样:
enter image description here

我想这样创建:

enter image description here

不是这样--->

enter image description here

提前致谢。

最佳答案

您可以通过程序检测开/关状态并设置图像。

[YourSwitch addTarget:self action:@selector(switchToggled:) forControlEvents: UIControlEventTouchUpInside];

    - (void) switchToggled:(id)sender {
        UISwitch *mySwitch = (UISwitch *)sender;
        if ([mySwitch isOn]) {
            [switchControl setThumbTintColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"Thumb.png"]]];
        } else {
            [switchControl setThumbTintColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"Thumb.png"]]];
        }
    }

关于ios - 如何在StoryBoard中为UISwitch设置“打开图像”和“关闭图像”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41138456/

相关文章:

ios - uploadTaskWithStreamedRequest 中的 AFNetworking 错误

iphone - didReceiveMemoryWarning - 手动卸载 View ?

objective-c - <CFData 0x100516c60 [0x7fff71adaea0]>{长度 = 6,容量 = 6,字节 = 0x0022412b03ad}

html - iOS safari 支持播放跨域音频吗?

ios - 有没有办法访问 UITextField 的布局管理器

ios - 仅使用 iFrame 在 UIWebView 中播放 youtube 视频

iphone - 动画时设置属性两次

objective-c - 我怎样才能让我的 setter 设置?

iphone - 在 UIViewController 上为 UIWebView 设置动画

ios - 在 Swift 中覆盖一个 var