像 Apple Music 这样的 UISlider
UISlider like Apple Music
新的 Apple Music 非常轻巧,极简和定制 UISlider
。 UISlider
图像似乎是在它的 drawRect()
方法中绘制的。如何制作类似的东西?
UISlider
exposes properties so you can modify the tint color or images of the “thumb” (the circle part) and the track to the left and right of the thumb. You can also subclass and provide different frames for the track and thumb. You can also adjust these properties on all sliders in your app using UIAppearance
.
This Ray Wenderlich tutorial 介绍了如何自定义滑块以及许多其他控件的外观。要点,以防 link 下降:
UIImage *minImage = [[UIImage imageNamed:@"slider_minimum"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
UIImage *maxImage = [[UIImage imageNamed:@"slider_maximum"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
UIImage *thumbImage = [UIImage imageNamed:@"thumb"];
[[UISlider appearance] setMaximumTrackImage:maxImage
forState:UIControlStateNormal];
[[UISlider appearance] setMinimumTrackImage:minImage
forState:UIControlStateNormal];
[[UISlider appearance] setThumbImage:thumbImage
forState:UIControlStateNormal];
新的 Apple Music 非常轻巧,极简和定制 UISlider
。 UISlider
图像似乎是在它的 drawRect()
方法中绘制的。如何制作类似的东西?
UISlider
exposes properties so you can modify the tint color or images of the “thumb” (the circle part) and the track to the left and right of the thumb. You can also subclass and provide different frames for the track and thumb. You can also adjust these properties on all sliders in your app using UIAppearance
.
This Ray Wenderlich tutorial 介绍了如何自定义滑块以及许多其他控件的外观。要点,以防 link 下降:
UIImage *minImage = [[UIImage imageNamed:@"slider_minimum"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
UIImage *maxImage = [[UIImage imageNamed:@"slider_maximum"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
UIImage *thumbImage = [UIImage imageNamed:@"thumb"];
[[UISlider appearance] setMaximumTrackImage:maxImage
forState:UIControlStateNormal];
[[UISlider appearance] setMinimumTrackImage:minImage
forState:UIControlStateNormal];
[[UISlider appearance] setThumbImage:thumbImage
forState:UIControlStateNormal];