Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can we change the text on the uiSwitch

can we change the text which is on the UISwitch, i.e. On & Off. i have tried the following code but its crashing

crashLog:

Terminating app due to uncaught exception NSInvalidArgumentException, reason: '-[UISwitch setLeftLabelText:]: unrecognized selector sent to instance 0x4c65020'**

switcher = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];
[switcher addTarget:self action:@selector(switchAction:)
forControlEvents:UIControlEventValueChanged];

// swit = [[UISwitch alloc] initWithFrame:CGRectZero];
[switcher setCenter:CGPointMake(160.0f,260.0f)];
[switcher setLeftLabelText: @"Female"];
[switcher setRightLabelText: @"Male"];
[[switcher rightLabel] setFont:[UIFont fontWithName:@"Georgia" size:16.0f]];
[[switcher leftLabel] setFont:[UIFont fontWithName:@"Georgia" size:16.0f]];
[[switcher leftLabel] setTextColor:[UIColor yellowColor]];

cell.accessoryView = switcher;
switcher.tag = indexPath.row;    
like image 502
Ravi Avatar asked May 23 '11 12:05

Ravi


2 Answers

Use this

http://www.catamount.com/blog/1063/uicustomswitch-customizing-uiswitch-color-it-change-labels/

like image 102
adam Avatar answered Sep 20 '22 15:09

adam


Have a look at this : http://osiris.laya.com/projects/rcswitch/ It is allowing many customization (including text)

like image 37
Sylverb Avatar answered Sep 23 '22 15:09

Sylverb