Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.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
Iphone 以编程方式创建UIButton的新行_Iphone_Objective C - Fatal编程技术网

Iphone 以编程方式创建UIButton的新行

Iphone 以编程方式创建UIButton的新行,iphone,objective-c,Iphone,Objective C,目前我正在水平创建一行UIButton(0,1,2,3) int x=0; for (int i=0; i<4; i++) { UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame = CGRectMake(10+x,20, 100, 100); x=x+120; [btn.titleLabel setFont:[UIFont fontWithName:@"Hel

目前我正在水平创建一行UIButton(0,1,2,3)

int x=0;

for (int i=0; i<4; i++) {

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(10+x,20, 100, 100);
    x=x+120;

    [btn.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:17.0]];
    btn.tag=i;
    NSString *str=[NSString stringWithFormat:@"%d",btn.tag];
    [btn setTitle:str forState:UIControlStateNormal];

    [btn setBackgroundColor:[UIColor redColor]];

    [self.view addSubview:btn];


}
intx=0;
对于(int i=0;i
使用如下
int x=0;
int y=20;
对于(int i=0;i
use like below

int x=0;
int y = 20;
for (int i=0; i<20; i++) //20 = total button
{
     UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
     btn.frame = CGRectMake(10+x,y, 100, 100);
     x=x+120;
     [self.view addSubview:btn];
    if((i+1)%4==0)//4 means how many buttons you need for a row
    {
        y+=110;
        x=0;
    }
 }