キーボード用に26個のボタンを描きたいです。3行あります。最初の行には 10 個のボタンがあり、2 番目の行には 9 個のボタンがあり、3 番目の行には 7 個のボタンがあります。ボタン間のスペースは 5 です。各ボタンの幅は 27、高さは 40 です。それらを同時に描画するにはどうすればよいですか?
1 に答える
1
このようにボタンを押すことができます:- それはあなたの問題の解決策ではありませんが.. あなたはまだそのコードからアイデアを得るでしょう.-
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;
}
}
このようなボタンが表示されます
于 2012-09-05T04:53:43.597 に答える