我有一个最小值为0且最大值为100的UISlider。我需要在滑块上显示0-100之间的中间值,如10,20,30 ... 90。请建议
答案 0 :(得分:4)
您可以将标签作为子视图添加到UISlider:
- (void)addLabelsToSlider:(UISlider*)slider{
for(int i=0;i<=100;i+=10){
UILabel *label = [[UILabel alloc] init];
label.font = [UIFont systemFontOfSize:10];
label.text = [NSString stringWithFormat:@"%d",i];
[label sizeToFit];
CGFloat labelX = (slider.frame.size.width/10)*i/10;
CGFloat labelY = slider.frame.size.height-label.frame.size.height/2;
label.center = CGPointMake(labelX, labelY);
[slider addSubview:label];
}
}