![](/img/trans.png)
[英]how to increase and decrease circle size in uislider with value change
[英]How to increase the size of the max track of a UISlider?
我想添加一个大小从最小到最大不同的 UISlider。
这是我需要的一个例子:
我尝试使用一些方法,例如:
- (CGRect)minimumValueImageRectForBounds:(CGRect)bounds;
- (CGRect)maximumValueImageRectForBounds:(CGRect)bounds;
- (CGRect)trackRectForBounds:(CGRect)bounds;
- (CGRect)thumbRectForBounds:(CGRect)bounds trackRect:(CGRect)rect value:(float)value;
但我无法让它工作......
关于您如何实现这一目标的任何建议或链接?
您需要继承 UISlider。 如果你在运行时创建 UISlider 你应该使用initWithFrame
否则initWithCoder
。
@implementation slider
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder:coder];
if (self) {
// At certain point images swap, that is why you need images fit to your UISlider size.
UIImage *sliderLeftImg = [[UIImage imageNamed: @"slider2"] stretchableImageWithLeftCapWidth: 10 topCapHeight: 0];
UIImage *sliderRightImg = [[UIImage imageNamed: @"slider"] stretchableImageWithLeftCapWidth: 10 topCapHeight: 0];
[self setMinimumTrackImage: sliderLeftImg forState: UIControlStateNormal];
[self setMaximumTrackImage: sliderRightImg forState: UIControlStateNormal];
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
我绘制的示例图像草率循环,您需要更好的。
最后结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.