如何以编程方式更改UISlider的拇指图像大小 [英] How to change size of thumb image of UISlider programmatically
本文介绍了如何以编程方式更改UISlider的拇指图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想制作自定义UISlider,
这样的东西
I would like to make the custom UISlider, something like this
| o ---------- | - > | ----- O ------ | - > |------------〇|
|o----------| -> |-----O------| -> |------------〇|
thumbImage
将会很小在最小值处,它会在滑块值增加时增加大小,否则会减小。
the thumbImage
will be small at the minimum value, it will increase the size during the slider value increase, otherwise it will decrease.
有人知道怎么做吗?
推荐答案
您可以使用以下代码:
+ (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
//UIGraphicsBeginImageContext(newSize);
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
取自这里。
您将获得的额外工作将是方法A ,当 UISlider的
值发生变化时,将调用 imageWithImage:scaledToSize:
。
The extra work you will have, will be a method A that will call the imageWithImage:scaledToSize:
when the UISlider's
value changes.
这篇关于如何以编程方式更改UISlider的拇指图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文