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

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