uiswitch

Select UITableView's row when tapping on its UISwitch in Swift

孤街浪徒 提交于 2019-12-03 08:51:21
问题 This question has been approached here in Objective-C. But I am working in Swift and have a similar question. Once successfully created, how do I select the UITableView's row when I tap on its UISwitch? I have a boolean in my model and would like to toggle that boolean based on the switches on/off state. I have some programmatically created cells that contain switches... View Controller: var settings : [SettingItem] = [ SettingItem(settingName: "Setting 1", switchState: true), SettingItem

UISwitch setOn(:, animated:) does not work as document

岁酱吖の 提交于 2019-12-03 07:12:23
As Apple's document write, UISwitch 's function setOn(on: Bool, animated: Bool) does not send action. It works fine before iOS 10, but it will send action after I call it in iOS 10. I call it in "ValueChanged" event to force switch back, so I got this event action twice. is it a bug in iOS 10? DispatchQueue.main.async { sender.setOn(flag, animated: animated) } it works for me in Xcode 8. but call UISwitch.setOn(_:animated:) directly on main thread doesn't work. Update thanks to @codiction: UISwitch.setOn(_:animated:) can be called direclty on main thread, but can't be called directly in

How do I make a UISwitch under iOS 7 not take the background colour of the view behind it?

梦想的初衷 提交于 2019-12-03 06:51:03
问题 It looks like this whenever off: While I'd prefer more of a grey background. Do I really have to use a UIImageView? 回答1: Here is how I changed the fill color of my iOS7 UISwitch. First you need to import QuartzCore. #import <QuartzCore/QuartzCore.h> 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

Swift/UISwitch: how to implement a delegate/listener

别来无恙 提交于 2019-12-03 05:42:37
In my UITableViewController I have a custom cell which contains a switcher which is the following: import Foundation import UIKit class SwitchCell: UITableViewCell { @IBOutlet weak var label : UILabel! @IBOutlet weak var switchEmail : UISwitch! func setEditable(canEdit:Bool) { if (canEdit) { self.switchEmail.enabled = true self.label.highlighted = false } else { self.switchEmail.enabled = false self.label.highlighted = true } } func configureCellWithSwitch(labelText:String, switchValue:Bool, enabled:Bool) { var labelFrame:CGRect = self.label.frame labelFrame.size.height = Settings.labelHeight

Save and Load UISwitch state

[亡魂溺海] 提交于 2019-12-03 05:06:46
I want to save the swtich state and load it when the program restarted. [[NSUserDefaults standardUserDefaults] setBool:switchControl.on forKey:@"switch"]; [[NSUserDefaults standardUserDefaults] synchronize]; This is the saving part BOOL test= [[NSUserDefaults standardUserDefaults] boolForKey:@"switch"]; NSLog(@"%@",test?@"YES":@"NO"); if(test == YES) [switchControl setOn:YES animated:YES]; else [switchControl setOn:NO animated:YES]; This is the part that is need to be set the switch to its value.I did this in viewdidload method because when i close the application and restarted it i want the

UISwitch - change from on/off to yes/no

只谈情不闲聊 提交于 2019-12-03 04:22:49
问题 does anyone know of a way I can change the text label for on and off to yes and no. I did it with ((UILabel *)[[[[[[switchControl subviews] lastObject] subviews] objectAtIndex:2] subviews] objectAtIndex:0]).text = @"Yes"; ((UILabel *)[[[[[[switchControl subviews] lastObject] subviews] objectAtIndex:2] subviews] objectAtIndex:1]).text = @"No"; However, with the release of iOS 4.2, this is no longer supported (this probably wasn't recommended by Apple anyway) My client is insisting on yes/no

Changing UISwitch width and height

两盒软妹~` 提交于 2019-12-03 01:21:28
I am trying to change the default height and width of a UISwitch element in iOS, but unsuccessfully. Can you change the default height and width of a UISwitch element? Should the element be created programmatically? William George I tested the theory and it appears that you can use a scale transform to increase the size of the UISwitch UISwitch *aSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(120, 120, 51, 31)]; aSwitch.transform = CGAffineTransformMakeScale(2.0, 2.0); [self.view addSubview:aSwitch]; Not possible. A UISwitch has a locked intrinsic height of 51 x 31 . You can force

iPhone: Save boolean into Core Data

时光毁灭记忆、已成空白 提交于 2019-12-03 00:35:45
问题 I have set up one of my core data attributes as a Boolean. Now, I need to set it, but XCode keeps telling me that it may not respond to setUseGPS. [ride setUseGPS: useGPS.on]; What is the method for setting a boolean in core data? All my other attributes are set this way, and they work great. So, not sure why a boolean does not work to be set this way? 回答1: Core Data "does not have" a Boolean type (it does, but it is an NSNumber). So to set the equivalent of useGPS = YES. [entity setUseGPS:

Select UITableView's row when tapping on its UISwitch in Swift

烈酒焚心 提交于 2019-12-02 21:24:55
This question has been approached here in Objective-C. But I am working in Swift and have a similar question. Once successfully created, how do I select the UITableView's row when I tap on its UISwitch? I have a boolean in my model and would like to toggle that boolean based on the switches on/off state. I have some programmatically created cells that contain switches... View Controller: var settings : [SettingItem] = [ SettingItem(settingName: "Setting 1", switchState: true), SettingItem(settingName: "Setting 2", switchState: true) ] override public func tableView(_tableView: UITableView,

How do I make a UISwitch under iOS 7 not take the background colour of the view behind it?

一个人想着一个人 提交于 2019-12-02 20:29:24
It looks like this whenever off: While I'd prefer more of a grey background. Do I really have to use a UIImageView? Here is how I changed the fill color of my iOS7 UISwitch. First you need to import QuartzCore. #import <QuartzCore/QuartzCore.h> 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]; This will give you a UISwitch with a custom off