Reputation: 754
I need to change the text on UISwitch and for that I have tried below code,
((UILabel *)[[[[[[_agreeAgb subviews] lastObject] subviews] objectAtIndex:2] subviews] objectAtIndex:0]).text = @"Foo";
((UILabel *)[[[[[[_agreeAgb subviews] lastObject] subviews] objectAtIndex:2] subviews] objectAtIndex:1]).text = @"Bar";
But It crashed at objectAtIndex
Is there any other way to do that other than making customized UISwitch?
Upvotes: 1
Views: 3425
Reputation: 4536
Another option for a custom UISwitch: https://github.com/alexnauda/ERScrollSwitch
Upvotes: 0
Reputation: 66
Now there's a better solution for this. Anyone needing a custom switch should check https://github.com/domesticcatsoftware/DCRoundSwitch
Upvotes: 0
Reputation: 51374
Never use such hacking techniques to modify the built-in UIControls. In future, they may cease to work in case the implementation of the controls change in the successive updates of iOS.
If you want to customize UISwitch
with your own text, you can instead you use UISegmentedControl
with your new texts. For example, if you want to get the gender of the user, instead of changing the UISwitch's on and off labels text, you can use segmented control with two items "Male" & "Female".
Upvotes: 6
Reputation: 52565
You don't say which objectAtIndex:
is causing the crash, but, in any case, it's moot: UISwitch
does not currently allow customising of the labels.
Upvotes: 0