我有一个UISlider
(最少 1 个,最多 10 个)。我希望它的拇指有一个UILabel
放置在它的顶部,在移动时不断更新和更改其文本UISlider
的拇指。所以,我从UISlider
并添加了一个UILabel
但一旦拇指移动,标签似乎会覆盖自身,而不会删除以前的值。
- (IBAction)SnoozeSliderValueChanged:(id)sender {
UIImageView *handleView = [_snoozeSlider.subviews lastObject];
UILabel *label = [[UILabel alloc] initWithFrame:handleView.bounds];
label.text = [NSString stringWithFormat:@"%0.0f", self.snoozeSlider.value];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = NSTextAlignmentCenter;
[handleView addSubview:label];
}
最初,
然后,当我开始拖动时,
我希望标签在拇指移动时擦除以前的值并显示当前值。如有任何帮助,我们将不胜感激。谢谢!
- (IBAction)SnoozeSliderValueChanged:(id)sender {
//Get the Image View
UIImageView *handleView = [_snoozeSlider.subviews lastObject];
// Get the Slider value label
UILabel *label = (UILabel*)[handleView viewWithTag:1000];
// If the slider label not exist then create it and add it to the Handleview. So handle view will have only one slider value label, so no more memory issues & not needed to remove from superview.
// Creation of object is Pain to iOS. So simply reuse it by creating only once.
// Note that tag setting below, which will helpful to find out that view presents in later case
if (label==nil) {
label = [[UILabel alloc] initWithFrame:handleView.bounds];
label.tag = 1000;
label.backgroundColor = [UIColor clearColor];
label.textAlignment = NSTextAlignmentCenter;
[handleView addSubview:label];
}
// Update the slider value
label.text = [NSString stringWithFormat:@"%0.0f", self.snoozeSlider.value];
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)