如何将另一个图像添加到滑块的缩略图或如何添加两个缩略图图像?

How to add a another image to Thumb of a slider or How to add two thumb images?

我正在使用 storyboards.I 构建 ios 应用程序,现在面临一个严重问题。我以编程方式创建了滑块。我添加了拇指图像作为我自己的自定义图像。我想在单击按钮时增加和减少宽度。这些都工作正常。我唯一想做的是,我想在此缩略图下添加另一个图像。新添加的图像应与拇指图像相应移动。

此方法将创建很多 complications.Better 创建自定义 slider.Everything 必须以编程方式创建。

如下所示声明视图和框架。

UIView *slider,*timeLine,*mainView;
UIView *thumb;
CGRect sliderFrame,thumbFrame;
-(void)createTimeLine
{
    timeLine = [[UIView alloc]initWithFrame:CGRectMake(0, 0, mainView.frame.size.width, 10)];
    timeLine.backgroundColor=[UIColor colorWithRed:224.0/255.0f green:224.0/255.0f blue:224.0/255.0f  alpha:1.0];
    [mainView addSubview:timeLine];

    [self createSlider];
    [self createThumb];

}
-(void)createSlider
{
    sliderFrame=CGRectMake(50, 0, delta, 10);
    slider=[[UIView alloc]initWithFrame:sliderFrame];
    slider.backgroundColor=[UIColor colorWithRed:0.0/255.0f green:102.0/255.0f blue:0.0/255.0f  alpha:1.0];
    [mainView addSubview:slider];
    [slider bringSubviewToFront:mainView];
}
-(void)createThumb{
    UIImage * thumbImage = [UIImage imageNamed:@"games@2x.png"];
    float actualHeight = thumbImage.size.height;
    float actualWidth = thumbImage.size.width;
    thumbFrame = CGRectMake((fabs(actualWidth - sliderFrame.size.width))/2,timeLine.frame.size.height,actualWidth,actualHeight);
    thumb=[[UIView alloc]initWithFrame:thumbFrame];
    thumb.center = CGPointMake(sliderFrame.origin.x + sliderFrame.size.width/2, sliderFrame.size.height+thumbFrame.size.height/2);
    thumb.backgroundColor= [UIColor colorWithPatternImage:thumbImage];
    thumb.userInteractionEnabled = YES;

    [mainView insertSubview:thumb atIndex:mainView.subviews.count];

    UIPanGestureRecognizer *move=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(drag:)];
    move.maximumNumberOfTouches = 1;
    move.minimumNumberOfTouches = 1;
    [thumb addGestureRecognizer:move];
}
-(void)drag:(UIPanGestureRecognizer *)panGestureRecognizer {
    CGPoint touchLocation = [panGestureRecognizer locationInView:mainView];
    if (panGestureRecognizer.state == UIGestureRecognizerStateBegan) {
    }
    else if (panGestureRecognizer.state == UIGestureRecognizerStateChanged) {
        if ((touchLocation.x>(timeLine.frame.origin.x-(thumbFrame.size.width/2))) && (touchLocation.x <= (timeLine.frame.size.width-(thumbFrame.size.width/2))))
        {
            thumbFrame.origin.x =touchLocation.x;
            thumb.frame = thumbFrame;
            sliderFrame.origin.x = touchLocation.x + (thumbFrame.size.width - sliderFrame.size.width)/2;
            slider.frame = sliderFrame;

        }

    } else if (panGestureRecognizer.state == UIGestureRecognizerStateEnded) {
    }
}

Pangesture 用于移动 thumbImage。