Another UISwitch user question

I looked at the stack overflow to answer this question, and I can only find ways that worked on 4.1 and lower, but for 4.2.1 and higher I cannot find a new way to get the text ON and OFF to change. Is there a way to change it to say yes and no. This is what I have:

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 to change UISwitch text? Or it would be easier if I had to make two images and use animation to make them flow, for example, this is a normal UISwitch.

+3
source share
1 answer

I wrote my own switch class. Hope this helps. http://cl.ly/4OQN

EDIT: , , :

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]];
+1

Source: https://habr.com/ru/post/1790015/


All Articles