自定义 UISilder 的拇指

Customize UISilder's thumb

我已经更改了 UISlider thumb image.But 我无法更改图像的大小

 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)