【发布时间】:2016-01-06 11:08:58
【问题描述】:
我以编程方式创建了一个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)];
我的问题是我应该使用哪个约束才能在每个设备中正确显示它。在这里,我附上了它在 6s 和 ipad pro 上的显示方式。如何让 ipad pro 的视觉效果和 6s 一样。
按钮锁定 6 秒
请帮助我。 谢谢
【问题讨论】:
标签: ios uiscrollview uibutton autolayout constraints