UISlider点击轴改变滑块位置

阅读更多

#import 

@interface MySlider : UISlider {
}

@end


#import "MySlider.h"

@implementation MySlider

- (id)initWithFrame:(CGRect)frame {
	self = [super initWithFrame:frame];
	
	return self;
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    CGRect t = [self trackRectForBounds: [self bounds]]; 
    float v = [self minimumValue] + ([[touches anyObject] locationInView: self].x - t.origin.x - 4.0) * (([self maximumValue]-[self minimumValue]) / (t.size.width - 8.0)); 
    [self setValue: v]; 
    [super touchesBegan: touches withEvent: event]; 
}


@end

你可能感兴趣的:(UISlider,滑块,位置,点击)