Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Another custom UISwitch question

I have looked all over stack overflow, for the answer to this question, and i can only find ways which worked on 4.1 and below, but for 4.2.1 and above, i can't find a new way of getting the text of ON and OFF to change. Is there a way of changing it to say Yes and No. This is what I have currently:

UISwitch *switchControl = [[UISwitch alloc] initWithFrame:frame];
    [switchControl addTarget:self action:action forControlEvents:UIControlEventValueChanged];
    switchControl.backgroundColor = [UIColor clearColor];
    switchControl.on = value;
    [cell addSubview:switchControl];
    [switchControl release];

What would be the easiest way of changing the text of the UISwitch? Or would it be easier if i was to make two images and using animation to make them flow, like it is a normal UISwitch.

like image 567
Alex Trott Avatar asked Jul 01 '26 23:07

Alex Trott


1 Answers

I wrote up a custom switch class. Hope this helps. http://cl.ly/4OQN

EDIT: Also, maybe try this:

switchView = [[UICustomSwitch alloc] initWithFrame:CGRectZero];
[switchView setCenter:CGPointMake(160.0f,260.0f)];
[switchView setLeftLabelText: @"Foo"];
[switchView setRightLabelText: @"Bar"];
[[switchView rightLabel] setFont:[UIFont fontWithName:@"Georgia" size:16.0f]];
[[switchView leftLabel] setFont:[UIFont fontWithName:@"Georgia" size:16.0f]];
[[switchView leftLabel] setTextColor:[UIColor yellowColor]];
like image 51
Frankrockz Avatar answered Jul 04 '26 13:07

Frankrockz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!