在设置UISlider最大值和最小值的image时导致左右两边间隙很大
解决方案
写一个继承UISlider的子类重写trackRectForBoundsCGRect)bounds方法
@interface CustomSlider : UISlider
@end
@implementation CustomSlider
// 控制slider的宽和高,这个方法才是真正的改变slider滑道的高的
- (CGRect)trackRectForBoundsCGRect)bounds {//返回滑道大小
bounds.origin.x = 20;
bounds.origin.y = (bounds.size.height - 2)/2.0;
bounds.size.height = 2;
bounds.size.width = bounds.size.width - 40;
return bounds;
}
@end
或者
- (CGRect)thumbRectForBoundsCGRect)bounds trackRectCGRect)rect valuefloat)value {
rect.origin.x=rect.origin.x-10;
rect.size.width=rect.size.width+20;
return CGRectInset([superthumbRectForBounds:bounds trackRect:rect value:value],10,10);
} |