0
我現在創建了83個按鈕動態現在我想爲它設置自動佈局。如何 我可以編碼? 我實現了以下代碼以生成動態按鈕。如何在iOS中爲多個動態按鈕添加自動佈局?
-(void)DynamicButton
{
int yPossion = 150, xPossion = 44; int temp = 0;
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:self.view.frame];
[self.view addSubview:scrollView];
for (int i = 0; i<83; i++){
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
[aButton setTranslatesAutoresizingMaskIntoConstraints:YES];
[aButton setBackgroundColor:[UIColor blackColor]];
[aButton setBackgroundImage:[UIImage imageNamed:@"icon-menu.png"] forState:UIControlStateNormal];
[aButton setTitle:[NSString stringWithFormat:@" %d",i] forState:UIControlStateNormal];
[aButton setFrame:CGRectMake(xPossion, yPossion, 70, 60)];
aButton.highlighted=YES;
[scrollView addSubview:aButton];
xPossion += aButton.frame.size.width+35;
temp++;
if (temp==3) {
yPossion = aButton.frame.origin.y+aButton.frame.size.height+20;
temp = 0;
xPossion = 44;
yPossion += aButton.frame.size.width-15;
[scrollView setContentSize:CGSizeMake(scrollView.frame.size.width ,yPossion-50)];
}
}
}
how to add auto layout for multiple dynamic buttons in iOS?
列明智的三列 – chetan74 2014-10-08 11:22:20
我想要的按鈕? – chetan74 2014-10-08 11:30:05
如何從 – chetan74 2014-10-09 04:22:58