自定義一個繼承於UISlider的類 重寫touchesBegan方法:ide
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{spa
CGRect t = [self trackRectForBounds: [self bounds]];3d
float v = [self minimumValue] + ([[touches anyObject] locationInView: self].x - t.origin.x - 4.0) * (([self maximumValue]-[self minimumValue]) / (t.size.width - 8.0));orm
[self setValue: v];繼承
[super touchesBegan: touches withEvent: event];it
}io