Change the size of a UISlider thumbImage

老子叫甜甜 提交于 2019-12-04 15:29:10

The thumb will be the size of the image you provide. To get a 24pt by 24pt thumb, you must provide 48px by 48px (and 72x72 for @3) image. This also affects the slider frame.

You can define an extension to resize images on the fly if needed:

extension UIImage
{
    func imageWithImage(image: UIImage, scaledToSize newSize: CGSize) -> UIImage
    {    
         UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0)
         image.drawInRect(CGRectMake(0, 0, newSize.width, newSize.height))

         let newImage = UIGraphicsGetImageFromCurrentImageContext()    
         UIGraphicsEndImageContext()

         return newImage;
    }
}

That way you can even do cool stuff like have a slider where the thumb grows and shrinks, as it approaches max and min values.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!