Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何将另一个图像添加到滑块的拇指或如何添加两个拇指图像?_Ios_Uiimageview_Uibutton_Uislider - Fatal编程技术网

Ios 如何将另一个图像添加到滑块的拇指或如何添加两个拇指图像?

Ios 如何将另一个图像添加到滑块的拇指或如何添加两个拇指图像?,ios,uiimageview,uibutton,uislider,Ios,Uiimageview,Uibutton,Uislider,我正在使用故事板构建ios应用程序。我现在面临一个关键问题。我以编程方式创建了滑块。我添加了拇指图像作为我自己的自定义图像。我想增加和减少按钮点击宽度。这些都很好用。我想做的唯一一件事是,我想在这个拇指图像下添加另一个图像。新添加的图像应与thumb图像一起移动。此方法将产生许多复杂问题。最好创建自定义滑块。所有内容都必须以编程方式创建 声明视图和框架,如下所示 UIView *slider,*timeLine,*mainView; UIView *thumb; CGRect sliderFra

我正在使用故事板构建ios应用程序。我现在面临一个关键问题。我以编程方式创建了滑块。我添加了拇指图像作为我自己的自定义图像。我想增加和减少按钮点击宽度。这些都很好用。我想做的唯一一件事是,我想在这个拇指图像下添加另一个图像。新添加的图像应与thumb图像一起移动。

此方法将产生许多复杂问题。最好创建自定义滑块。所有内容都必须以编程方式创建

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

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) {
    }
}
UIView*滑块、*时间线、*主视图;
UIView*拇指;
CGRect滑块框架、指框;
-(无效)创建时间线
{
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];
[主视图添加子视图:时间线];
[自创滑块];
[自创拇指];
}
-(void)创建滑块
{
sliderFrame=CGRectMake(50,0,增量,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];
[主视图添加子视图:滑块];
[滑块将子视图带到前面:主视图];
}
-(void)createThumb{
UIImage*thumbImage=[UIImage ImageName:@”games@2x.png"];
浮动实际高度=thumbImage.size.height;
浮动实际宽度=thumbImage.size.width;
thumbFrame=CGRectMake((fabs(实际宽度-sliderFrame.size.width))/2,timeLine.frame.size.height,实际宽度,实际高度);
thumb=[[UIView alloc]initWithFrame:thumbFrame];
thumb.center=CGPointMake(sliderFrame.origin.x+sliderFrame.size.width/2,sliderFrame.size.height+thumbFrame.size.height/2);
thumb.backgroundColor=[uicolorWithPatternImage:thumbImage];
thumb.userInteractionEnabled=是;
[mainView insertSubview:thumb索引:mainView.subviews.count];
UIPanGestureRecognizer*move=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(drag:)];
move.MaximumNumberOfTouchs=1;
move.minimumnumberoftouchs=1;
[拇指添加手势识别器:移动];
}
-(无效)拖动:(UIPangEstureRecognitor*)PangEstureRecognitor{
CGPoint touchLocation=[PangestureRecognitor locationInView:mainView];
if(panGestureRecognizer.state==UIgestureRecognizerStateStart){
}
else if(panGestureRecognizer.state==UIGestureRecognizerStateChanged){
if((touchLocation.x>(timeLine.frame.origin.x-(thumbFrame.size.width/2))&(touchLocation.x