Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.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_Uiscrollview_Uibutton_Autolayout_Constraints - Fatal编程技术网

Ios 理解纵横比约束和乘数

Ios 理解纵横比约束和乘数,ios,uiscrollview,uibutton,autolayout,constraints,Ios,Uiscrollview,Uibutton,Autolayout,Constraints,我以编程方式创建了一个UIScrollview。我在这个滚动视图中添加了一些编程创建的按钮。按钮高度为30。但是按钮的宽度会根据屏幕大小而变化 float scrollYearX=btnLeftArrow.frame.origin.x+btnLeftArrow.frame.size.width+15; float scrollYearY=40.0; float scrollYearWidth=btnRightArrow.frame.origin.x-15-scrollYearX; float s

我以编程方式创建了一个
UIScrollview
。我在这个滚动视图中添加了一些编程创建的按钮。按钮高度为30。但是按钮的宽度会根据屏幕大小而变化

float scrollYearX=btnLeftArrow.frame.origin.x+btnLeftArrow.frame.size.width+15;
float scrollYearY=40.0;
float scrollYearWidth=btnRightArrow.frame.origin.x-15-scrollYearX;
float scrollYearHeight=50.0;
scrollYear=[[UIScrollView alloc] initWithFrame:CGRectMake(scrollYearX, scrollYearY, scrollYearWidth, scrollYearHeight)];

[scrollYear setShowsHorizontalScrollIndicator:NO];
[scrollYear setShowsVerticalScrollIndicator:NO];

[vwParent addSubview:scrollYear];
int buttonX=0;

for (int i=0; i<100; i++) {
    UIButton *btn=[[UIButton alloc] initWithFrame:CGRectMake(buttonX, 0, scrollYearWidth/5, 30)];
    [btn.titleLabel setFont:[UIFont fontWithName:@"HelveticaNeue" size:14.0]];

    int mod=i%2;
    if (mod==1) {
        [btn setTitle:@"-" forState:UIControlStateNormal];
        [btn.titleLabel setTextColor:[UIColor whiteColor]];

    }
    else
    {
        [btn addTarget:self action:@selector(yearClick :) forControlEvents:UIControlEventTouchUpInside];
        [btn setTitle:[NSString stringWithFormat:@"%li",(long)backYear] forState:UIControlStateNormal];
        if (backYear==year) {
            btnCurrentYear=btn;
            [btn setBackgroundImage:[UIImage imageNamed:@"yearSelect"] forState:UIControlStateNormal];
        }
        backYear++;
    }
    [scrollYear addSubview:btn];
    btnLast=btn;
    buttonX=buttonX+btn.frame.size.width;
}
[scrollYear setContentSize:CGSizeMake(btnLast.frame.origin.x+btnLast.frame.size.width, scrollYearHeight)];
[scrollYear setContentOffset:CGPointMake(btnCurrentYear.frame.origin.x-(btnLast.frame.size.width*2),0)];
float-scrollYearX=btnLeftArrow.frame.origin.x+btnLeftArrow.frame.size.width+15;
浮点数y=40.0;
float scrollYearWidth=btnRightArrow.frame.origin.x-15-scrollYearX;
浮动高度=50.0;
scrollYear=[[UIScrollView alloc]initWithFrame:CGRectMake(scrollYearX,scrollYearY,scrollYearWidth,scrollYearHeight)];
[滚动年设置ShowShorizontalsCrollinIndicator:否];
[scrollYear设置ShowsVerticalScrollIndicator:否];
[vwParent addSubview:scrollYear];
int buttonX=0;

对于(int i=0;i这是因为您的按钮背景宽度已缩放。您需要使用可调整大小的图像来保持圆形边缘。使用以下命令更改背景图像:

UIImage* backgroundImage = [UIImage imageNamed:@"yearSelect"];
backgroundImage = [backgroundImage resizableImageWithCapInsets:UIEdgeInsetsMake(0, backgroundImage.size.width/2-1, 0, backgroundImage.size.width/2)];
[btn setBackgroundImage:backgroundImage forState:UIControlStateNormal];

你所说的可调整大小的图像是什么意思?我如何使用它们?@user1960169查看UIImage API,应该有一个类似于可调整大小的图像的方法。现在我正在使用iPhone客户端,无法检查文档。