我对 uiview 进行了子类化,我在其中添加了两个 uiimageview,一个视图用于背景,另一个图像视图用于我想在触摸时移动的图像。我正在从视图控制器添加这个子类 uiview。以下是代码:
@interface CustomSlider : UIView
{
UIImageView *bgView;
UIImageView *customSliderImageView;
float minStartPoint,maxEndPoint;
}
- (id)initWithFrame:(CGRect)frame inView:(UIView*)mainView;
@end
@implementation CustomSlider
- (id)initWithFrame:(CGRect)frame inView:(UIView*)mainView {
if((self = [super init])) {
UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(15, 60, frame.size.width, frame.size.height)];
contentView.backgroundColor = [UIColor clearColor];
[mainView addSubview:contentView];
bgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"price_96.png"]];
bgView.frame = CGRectMake(5, 0, frame.size.width - 10, 8 );
[contentView addSubview:bgView];
customSliderImageView= [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"price_100.png"]];
customSliderImageView.frame = CGRectMake(20, 0, 35, frame.size.height);
[contentView addSubview:customSliderImageView];
minStartPoint = 0;
UIPanGestureRecognizer* pgr = [[UIPanGestureRecognizer alloc]
initWithTarget:self
action:@selector(handlePan:)];
[customSliderImageView addGestureRecognizer:pgr];
[pgr release];
}
return self;
}
@end