【发布时间】:2014-07-13 19:29:13
【问题描述】:
我想自定义我的 UISlider 以便能够显示附加照片中的步骤(顺便说一句,这是一个字体大小选择器,来自我的 iPhone 设置的本机控制)。我可以为最小值和最大值设置图像,但我无法显示步骤。我不需要 3rd 方库来执行此操作,我确信可以自定义 UISlider 来拥有它。
请帮忙。
提前致谢。
【问题讨论】:
我想自定义我的 UISlider 以便能够显示附加照片中的步骤(顺便说一句,这是一个字体大小选择器,来自我的 iPhone 设置的本机控制)。我可以为最小值和最大值设置图像,但我无法显示步骤。我不需要 3rd 方库来执行此操作,我确信可以自定义 UISlider 来拥有它。
请帮忙。
提前致谢。
【问题讨论】:
您可以在滑块后面添加一些子视图来显示步骤:
int numSteps = 5;
for(int i=0; i<numSteps; i++){
CGFloat x = i*CGRectGetWidth(slider.frame)/(numSteps-1);
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(x, CGRectGetMidY(slider.frame)-5, 1, 10)];
v.backgroundColor = [UIColor lightGrayColor];
[slider.superview insertSubView:v belowSubview:slider];
UILabel numberLabel = [[UILabel alloc] init];
numberLabel.text = [NSString stringWithFormat:@"%i",i];
numberLabel.font = [UIFont systemFontOfSize:13];
[numberLabel sizeToFit];
numberLabel.center = CGPointMake(x, CGRectGetMidY(slider.frame)+CGRectGetHeight(numberLabel.frame)/2+7);
[slider.superview insertSubView:numberLabel belowSubview:slider];
}
【讨论】: