Thursday, December 5, 2013

How to modify UISwitch's text?

Online search says so:

-------------------------------

IB connection is established to change Text of UISwitch: for example mySwitch, change the text in the code:

((UILabel *) [[[[[[self.mySwitch subviews] lastObject] subviews] objectAtIndex: 2] subviews] objectAtIndex: 0]) text = @ "Foo";
.
((UILabel *) [[[[[[self.mySwitch subviews] lastObject] subviews] objectAtIndex: 2] subviews] objectAtIndex: 1]) text = @ "Bar";
.
-------------------------------

All the same, according to this try, given the array bounds

How to do this
Reply:
uiswich
Internal subviews does not seem

You really want to use on their own custom calculations. The same function can be achieved, the effect is not quite right. . .

Indicates weakness. . .



Reply:
Looks like only their own definition,,

Reply:
if (self.numberOfSegments) {
for (id seg in [self subviews]) {
for (id label in [seg subviews]) {
if ([label isKindOfClass: [UILabel class]]) {
UILabel * temp = label;
[Temp setText: @ "text"];
}
}
}
}

Reply:
UISwitch view tree traversal, output
UISwitch: UIControl
-UIView: UIResponder
-UIView: UIResponder
Without
UISwitch: UIControl
-_UISwitchSlider: UISlider
- UIImageView: UIView
- UIImageView: UIView
- UIView: UIResponder
--- UILabel: UIView
--- UILabel: UIView
- UIImageView: UIView
Therefore, this method does not work, and for derivatives or custom?
Reply:
Custom! ! ! ! !

No comments:

Post a Comment