我已经更改了UISlider拇指图像。但是我无法更改图像的大小

 var image=UIImage(named: "thumb.png")
  slider.setThumbImage(image, forState: UIControlState.Normal)

我找到了滑块功能slider.thumbRectForBounds,但是对我没有帮助

最佳答案

试试看

func imageWith(image : UIImage, scaledToSize:CGSize ) -> UIImage {
    UIGraphicsBeginImageContextWithOptions(scaledToSize, false, 0.0);
    image.drawInRect(CGRectMake(0, 0, scaledToSize.width, scaledToSize.height))
    let newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}


var image = UIImage(named: "thumb.png")
slider.setThumbImage(imageWith(image, scaledToSize: <YOUR_SIZE>), forState: UIControlState.Normal)

关于ios - 自定义UISilder的拇指,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32903565/

10-15 18:35