您好我想添加多個UIButtons
編程。其實我有NSMutableArray
。我想創造NSMutableArray
許多許多UIButtons
儘可能多的元素。我也希望在UIView
的每一行中必須有3個UIButton。創建UIButton
不是男人的問題問題我寫算法,用於動態創建buttons
。這是代碼提前如何添加多發uibuttons編程
-(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);
}
你在哪裏設置你的按鈕你檢查 – Rajneesh071 2013-04-22 09:28:49
我的代碼的XCOORD? – Rajneesh071 2013-04-23 07:45:05