UISwitch in a UITableView cell

Setting it as the accessoryView is usually the way to go. You can set it up in tableView:cellForRowAtIndexPath: You may want to use target/action to do something when the switch is flipped. Like so: – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { switch( [indexPath row] ) { case MY_SWITCH_CELL: { UITableViewCell *aCell = [tableView dequeueReusableCellWithIdentifier:@”SwitchCell”]; if( … Read more

Changing the text on a UISwitch

As of iOS 6, you can set @property(nonatomic, retain) UIImage *offImage; @property(nonatomic, retain) UIImage *onImage; Docs say: 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 final appearance. The size of this image must be less than or equal … Read more

How do i keep UISwitch state when changing ViewControllers?

Xcode 8.3 • Swift 3.1 import UIKit class ViewController: UIViewController { @IBOutlet weak var switchButton: UISwitch! override func viewDidLoad() { super.viewDidLoad() switchButton.isOn = UserDefaults.standard.bool(forKey: “switchState”) } @IBAction func saveSwitchPressed(_ sender: UISwitch) { UserDefaults.standard.set(sender.isOn, forKey: “switchState”) } }

iOS7 UISwitch its Event ValueChanged: Calling continuously is this Bug or what..?

Please see the following code: -(void)viewDidLoad { [super viewDidLoad]; UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(130, 235, 0, 0)]; [mySwitch addTarget:self action:@selector(changeSwitch:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:mySwitch]; } – (void)changeSwitch:(id)sender{ if([sender isOn]){ NSLog(@”Switch is ON”); } else{ NSLog(@”Switch is OFF”); } }

How to customize UISwitch button in iphone?

You can not modify UISwitch control unless and until you write your own control, But best way so far, you can used UISegmentControl and handle event on it to switch the on.png and off.png images. UISegmentedControl* switchView=[[UISegmentedControl alloc] initWithItems:[[[NSMutableArray alloc] initWithObjects:@”On”,@”Off”,nil] autorelease]]; [switchView setFrame:CGRectMake(20,365,140,28)]; switchView.selectedSegmentIndex=0; switchView.segmentedControlStyle=UISegmentedControlStyleBar; [switchView setImage:[UIImage imageNamed:@”onSelected.png”] forSegmentAtIndex:0]; [switchView setImage:[UIImage imageNamed:@”off.png”] forSegmentAtIndex:1]; [switchView … Read more

Change color of UISwitch in “off” state

My solution with #swift2: let onColor = _your_on_state_color let offColor = _your_off_state_color let mSwitch = UISwitch(frame: CGRect.zero) mSwitch.on = true /*For on state*/ mSwitch.onTintColor = onColor /*For off state*/ mSwitch.tintColor = offColor mSwitch.layer.cornerRadius = mSwitch.frame.height / 2.0 mSwitch.backgroundColor = offColor mSwitch.clipsToBounds = true Result:

How to know the UITableview row number

Tags, subclasses, or view hierarchy navigation are too much work!. Do this in your action method: CGPoint hitPoint = [sender convertPoint:CGPointZero toView:self.tableView]; NSIndexPath *hitIndex = [self.tableView indexPathForRowAtPoint:hitPoint]; Works with any type of view, multi section tables, whatever you can throw at it – as long as the origin of your sender is within the cell’s … Read more