我们如果需要定制Slider的外观,就需要给它设置图片,设置图片时要注意初始化可拉伸图片对象的写法。要把方法连着写,像这样写是可以的
UIImage *trackimg = [[UIImage imageNamed:@"slider-default-track_n"] resizableImageWithCapInsets:UIEdgeInsetsMake(3.0, 6.0, 3.0, 6.0)];
[slider setMinimumTrackImage:trackimg forState:UIControlStateNormal];
当初我为了方便计算CapInsets时使用算术表达式,所以想分开写,但这是不行的:
UIImage *trackimg2 = [UIImage imageNamed:@"slider-default-track_n"];
[trackimg2 resizableImageWithCapInsets:UIEdgeInsetsMake(trackimg2.size.height/ 2.0 - 1, trackimg2.size.width/ 2.0 - 1, trackimg2.size.height/ 2.0 - 1, trackimg2.size.width/ 2.0 - 1)];
[slider setMinimumTrackImage:trackimg2 forState:UIControlStateNormal];