I want to draw 26 buttons for keyboard. There are 3 rows. First row has 10 button, second has 9, and the third has 7. The space from one button to another is 5. Each button has width: 27 and height: 40. How can I draw them at the same time ?
You can button like this:- it is not the solution of ur problem but.. u will still get the idea from that code.-
objDelegate.redColorArray = [[NSMutableArray alloc] initWithObjects:@"255",@"215",@"242",@"198",@"204",@"119",@"217",@"149",@"112",@"79",@"247",@"55",@"0",@"0",@"255",@"16", nil];
objDelegate.greenColorArray = [[NSMutableArray alloc] initWithObjects:@"255",@"228",@"220",@"217",@"193",@"147",@"150",@"179",@"48",@"98",@"150",@"96",@"0",@"176",@"0",@"37", nil];
objDelegate.blueColorArray = [[NSMutableArray alloc] initWithObjects:@"255",@"189",@"219",@"241",@"218",@"60",@"148",@"215",@"160",@"40",@"70",@"146",@"0",@"80",@"0",@"63", nil];
UIButton *btn[16];
buttonArray = [[NSMutableArray alloc] init];
int x=0;
int y=0;
for (int i=0; i<16; i++)
{
btn[i] = [[UIButton alloc] initWithFrame:CGRectMake(x, y, 15, 15)];
[btn[i] setBackgroundColor:[UIColor colorWithRed:[[objDelegate.redColorArray objectAtIndex:i]floatValue]/255.0 green:[[objDelegate.greenColorArray objectAtIndex:i]floatValue]/255.0 blue:[[objDelegate.blueColorArray objectAtIndex:i]floatValue]/255.0 alpha:1]];
btn[i].tag = i;
[btn[i] addTarget:self action:@selector(setColor:) forControlEvents:UIControlEventTouchUpInside];
[buttonArray addObject:btn[i]];
[self addSubview:btn[i]];
x+=20;
if((i+1)%4==0)
{
x=0;
y+=20;
}
}
it will show button like this
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.