for 루프를 사용하여 9 개의 단추를 만들고 있는데, 한 번에 모든 단추에 액세스하기 때문에 배열에 단추를 저장하고 싶습니다.배열에 단추를 저장하고 싶습니다.
for(i = 0; i < 9; i++)
{
num1 = [UIButton buttonWithType:UIButtonTypeCustom];
[num1 setExclusiveTouch:YES];
[num1 setTag:tag_start+i];
num1.tag = currentTag;
currentTag++;
[num1 setTitle:[NSString stringWithFormat:@"%d",currentTag] forState:UIControlStateNormal];
[num1 setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
[num1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[num1.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:35.0]];
//Store the button in array
[numBtnArray addObject:num1];
NSLog(@"%d", numBtnArray.count); //it show 0 nothing in that array
if(i >= 5) {
num1.frame = CGRectMake(430, i*60-160, 50, 50);
}
else {
num1.frame = CGRectMake(350, i*60+140, 50, 50);
}
[num1 addTarget:self action:@selector(buttonFunction:) forControlEvents:UIControlEventTouchUpInside];
[num1 setBackgroundImage:[UIImage imageNamed:@"greyBtn.png"] forState:UIControlStateNormal];
[num1 setBackgroundImage:[UIImage imageNamed:@"greyBtn.png"] forState:UIControlStateHighlighted];
[self.view addSubview:num1];
}
액세스 한 번에 모든 버튼 ?? 이게 무슨 뜻이야 ?? –
이미 버튼을 배열 (numBtnArray)에 추가하고있는 것 같습니다. 당신의 질문은 정확히 무엇입니까? –
즉, 배열을 사용하여 코드 한 줄에있는 모든 9 개의 버튼의 색상을 변경하는 경우 – user3069029