iOS 5 如何更改 UISwitch 的文本?
我使用下面的代码(类别)来更改但它不起作用。
代码:(原始代码取自 iphone 食谱 第 8 章)
#import "UISwitch+Extended.h"
@interface UISwitch (extended)
- (void) setAlternateColors:(BOOL) boolean;
@end
@interface _UISwitchSlider : UISlider
@end
@implementation UISwitch (Extended)
- (_UISwitchSlider *) slider {
return [[self subviews] lastObject];
}
- (UIView *) textHolder {
return [[[self slider] subviews] objectAtIndex:1];
}
- (UILabel *) leftLabel {
return [[[self textHolder] subviews] objectAtIndex:0];
}
- (UILabel *) rightLabel {
return [[[self textHolder] subviews] objectAtIndex:1];
}
- (void) setLeftLabelText: (NSString *) labelText {
[[self leftLabel] setText:labelText]; //error occurred here.
}
- (void) setRightLabelText: (NSString *) labelText {
[[self rightLabel] setText:labelText];
}
请提供任何想法。
i used the code (categorie) below to change the bu it didn't works.
the code : (original code taken from iphone cookbook chapter 8)
#import "UISwitch+Extended.h"
@interface UISwitch (extended)
- (void) setAlternateColors:(BOOL) boolean;
@end
@interface _UISwitchSlider : UISlider
@end
@implementation UISwitch (Extended)
- (_UISwitchSlider *) slider {
return [[self subviews] lastObject];
}
- (UIView *) textHolder {
return [[[self slider] subviews] objectAtIndex:1];
}
- (UILabel *) leftLabel {
return [[[self textHolder] subviews] objectAtIndex:0];
}
- (UILabel *) rightLabel {
return [[[self textHolder] subviews] objectAtIndex:1];
}
- (void) setLeftLabelText: (NSString *) labelText {
[[self leftLabel] setText:labelText]; //error occurred here.
}
- (void) setRightLabelText: (NSString *) labelText {
[[self rightLabel] setText:labelText];
}
Any idea please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此代码通过索引访问子视图,它们在新的 iOS 中可能已更改。打印交换机的所有子视图并找到您需要的子视图。
This code accesses subviews by indexes and they may have changed in new iOS. Print all subviews of the switch and find ones you need.