iOS UISlider 經過點擊改變value

自定義一個繼承於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

相關文章
相關標籤/搜索