简介
使用继承uislider并重写一些方法并不能实现改变滑块大小的要求,这里需要一张与要求的大小相同的图片设置到滑块上就可以了
代码
-
下面是裁剪的代码
-
(UIImage*)image:(UIImage*)image scaleToSize:(CGSize)size{
UIGraphicsBeginImageContext(size);//size为CGSize类型,即你所需要的图片尺寸
[image drawInRect:CGRectMake(0,0, size.width, size.height)];
UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();return scaledImage;
}
-
-
下面是设置滑块图片的代码
UIImage *tempImage = [UIImage imageNamed:@"optometry_icon_point"];
UIImage *tempImage1 = [UIImage image:tempImage scaleToSize:CGSizeMake(50, 50)];
[tempView setThumbImage:tempImage1 forState:UIControlStateNormal];
[tempView setThumbImage:tempImage1 forState:UIControlStateHighlighted];