Tag: uiswitch

如何在iOS 7下创build一个UISwitch,而不是采用背后的视图的背景颜色?

看起来像这样每当closures: 虽然我更喜欢灰色背景。 我真的必须使用UIImageView吗?

为什么UISwitch onImage / offImage属性不适用于iOS 7?

有这两个选项/属性,并贬低他们的意义是什么? 从Apple文档: offImage The image displayed while the switch is in the off position. @property(nonatomic, retain) UIImage *offImage Discussion In iOS 7, this property has no effect. In iOS 6, this image represents the interior contents of the switch. The image you specify is composited with the switch's rounded bezel and thumb to create the […]

UISwitch不发送valueChanged事件时编程更改

我有一对UISwitches通过valueChanged事件连接到一个IBAction。 当触摸开关时,valueChanged事件触发正常。 但是,如果我以编程方式更改其中一个开关,它不会调用我的IBAction。 – (IBAction)switchChanged:(UISwitch *)sender { if (sender == self.shippingSwitch) { if (self.shippingSwitch.on && !self.PayPalSwitch.on) { [self.PayPalSwitch setOn:YES animated:YES]; } } if (sender == self.PayPalSwitch) { if (!self.PayPalSwitch.on) { // This is not working when the PayPal switch is set via the code above self.PayPalEmailField.backgroundColor = [UIColor grayColor]; self.PayPalEmailField.enabled = NO; if (self.shippingSwitch.on) { […]

默认的UISwitch为YES,然后用NSUserDefaults保存状态

我试图去的function是默认我的开关到setOn:YES的状态,但是一旦用户切换UISwitch在NSUserDefaults保存该开关的状态。 在我看来,我最好怎样去做这件事? 我目前有我的viewDidLoad下面的代码: if([[NSUserDefaults standardUserDefaults] boolForKey:@"lights"] == 0){ [lightsSwitch setOn:NO]; } 并在我的toggleLightSwitch:(id)sender : [[NSUserDefaults standardUserDefaults] setBool:lightsSwitch.isOn forKey:@"lights"]; 但function将默认为setOn:NO 。 由于NSUserDefault对于bool键默认为NO ,有没有办法解决这个问题?

自定义uiswitch图像?

我在我的iOS 6应用程序中有一个UISwitch,这是开启和closures的图像是自定义的。 self.testSwitch.onImage = [UIImage imageNamed:@"on"]; self.testSwitch.offImage = [UIImage imageNamed:@"off"]; 我使用77点宽和22点高的图像(视网膜154×44),如文件中所述。 但是我的图片不适合我的uiswitch,看起来很丑,默认的风格隐藏了我的图片,就像附加的图片一样。 我应该怎样设置才能使其工作正常?

如何检索UISwitch的UITableView行号?

我已经尝试了几种方法张贴在这里,但我不能让我的表充满开关返回改变的开关的单元格的索引值。 我正在以编程方式创build包含表的视图(没有xib)。 TableSandboxAppDelegate.m我在didFinishLaunchingWithOptions:实例化视图控制器didFinishLaunchingWithOptions: with: … TableSandboxViewController *sandboxViewController = [[TableSandboxViewController alloc] init]; [[self window] setRootViewController:sandboxViewController]; … TableViewController.h文件读取: @interface TableSandboxViewController : UITableViewController { NSMutableArray *_questionOrder; NSMutableArray *switchStates; } @end TableViewController.m cellForRowAtIndexPath:读取: UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainCell"]; UISwitch *theSwitch = nil; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MainCell"]; theSwitch = [[UISwitch alloc] initWithFrame:CGRectZero]; theSwitch.tag […]

Swift – 如何设置NSUserDefaults的初始值

我有一个名为soundSwitch的开关,我使用默认的用户保存button的状态如下: @IBAction func soundsChanged(sender: AnyObject) { if soundSwitch.on{ defaults.setBool(true, forKey: "SoundActive") print("Sound ON") }else{ defaults.setBool(false, forKey: "SoundActive") print("Sound OFF") } } 目前,当用户首次启动应用程序时,实际的默认值最初为false。 如果用户第一次启动应用程序并且尚未configuration它,我如何实现默认值为true。 我已经看到Objective-C中的方法,但没有在Swift中。 从我所看到的,你可以在应用程序委托中做一些如何操作,或者在一个plist文件中。 我怎么做那两个呢?

无法将types'NSObject – >() – > PostFeed'的值转换为期望的参数types'AnyObject?'

我以下面的方式添加一个UISwitch : let anonSwitch : UISwitch = { let mySwitch = UISwitch() mySwitch.on = false mySwitch.setOn(false, animated: false); mySwitch.tintColor = UIColor(red: (69/255.0), green: (209/255.0), blue: (153/255.0), alpha: 1.0) mySwitch.addTarget(self, action: #selector(handleAnonSwitch), forControlEvents: .ValueChanged) return mySwitch }() 现在,我在mySwitch.addTarget的self关键字上收到以下错误消息: Cannot convert value of type 'NSObject -> () -> PostFeed' to expected argument type 'AnyObject?' 我在我的所有其他addTarget函数为UIButton使用self ,我从来没有遇到这个错误

自定义开/关图像iOS 7.0 UI开关

在iOS 7交换机默认情况下不允许自定义开/关图像。 虽然我仍然可以在界面生成器中设置它们,但不会显示出来。 https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/TransitionGuide.pdf 过渡指南只是指出,它已经不是默认了。 大概有一种方法来改变,所以我使用我有的图像。

UISwitch setThumbTintColor导致崩溃(仅iOS 6)?

更新:从苹果收到一封邮件说,该错误/问题已被修复,下一个SDK版本将不会有这个问题。 和平! 我在我的AppDelegate的代码中有这个: – (void) customizeAppearance { [[UISwitch appearance] setOnTintColor:[UIColor colorWithRed:0 green:175.0/255.0 blue:176.0/255.0 alpha:1.0]]; [[UISwitch appearance] setTintColor:[UIColor colorWithRed:255.0f/255.0f green:255.0f/255.0f blue:255.0f/255.0f alpha:1.000f]]; [[UISwitch appearance] setThumbTintColor:[UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0]]; } 然后我调用- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 我也用ARC。 在iOS 6中,我的应用程序不断崩溃。 我启用NSZombie,它一直说: *** -[UIDeviceRGBColor release]: message sent to deallocated instance 0x9658eb0 现在我已经意识到上述的一个完美可重复的stream程。 当我在customAppearance中单独注释掉setThumbTintColor行时,一切正常。 当我使用setThumbTintColor行代替时,应用程序每次都以完全相同的方式崩溃。 这是UISwitch / setThumbTintColor / UIColor的任何人都知道的问题? […]