我想以UIButtons
编程方式添加多个。其实我有NSMutableArray
。我想UIButtons
在NSMutableArray
. 而且我还希望UIView
. 创造UIButton
对男人来说不是问题,对我来说写buttons
动态创建算法的问题。这是代码请纠正这个
-(IBAction)seeAll:(id)sender
{
if ([barBtn.title isEqualToString:@"See All"])
{
containerVw = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
[containerVw setBackgroundColor:[UIColor whiteColor]];
[srcVw removeFromSuperview];
[self.view addSubview:containerVw];
NSUInteger i;
int xCoord;
int yCoord=20;
int buttonWidth=80;
int buttonHeight=50;
int buffer = 10;
for (i = 1; i <= imageArray.count; i++)
{
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
aButton.frame = CGRectMake(xCoord, yCoord,buttonWidth,buttonHeight);
[aButton setBackgroundImage:[imageArray objectAtIndex:i-1] forState:UIControlStateNormal];
[aButton addTarget:self action:@selector(whatever:) forControlEvents:UIControlEventTouchUpInside];
[containerVw addSubview:aButton];
if (i%4 == 0 )
{
yCoord += buttonHeight + buffer;
}
NSLog(@"xcoordinate %i",xCoord);
NSLog(@"ycoordinate %i",yCoord);
}