그룹화 된 각 이미지에 대해 3 가지 UIButton이 있습니다. 각 이미지에 ID가 있습니다. 지금은 각 이미지에 대한 특수 ID가 있으며 그 태그로 버튼을 설정합니다.UIButton 용 특수 태그?
내가 탭하면 선택한 이미지의 배경 이미지를 변경하고 싶습니다. 문제는 3 개의 버튼에 동일한 태그가있어 오른쪽 버튼의 배경 이미지를 변경할 수 없다는 것입니다. 이 일에 더 나은 방법이
UIButton *likeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[likeButton setBackgroundColor:[UIColor clearColor]];
[likeButton setBackgroundImage:[UIImage imageNamed:@"icon_like_button.png"] forState:UIControlStateNormal];
[likeButton setBackgroundImage:[UIImage imageNamed:@"icon_like_button_hit.png"] forState:UIControlStateSelected];
[likeButton setBackgroundImage:[UIImage imageNamed:@"icon_like_button_hit.png"] forState:UIControlStateHighlighted];
[likeButton setBackgroundImage:[UIImage imageNamed:@"icon_like_button_hit.png"] forState:UIControlStateDisabled];
[likeButton setFrame:CGRectMake(13, 52 + (285 * count), 51, 55)];
[likeButton addTarget:self action:@selector(likeDudle:) forControlEvents:UIControlEventTouchDown];
[likeButton setTag:theIdInt];
[likeButton setTitle:@"no_like" forState:UIControlStateNormal];
[scrollView addSubview:likeButton];
- (IBAction)likeDudle: (id)sender {
NSInteger tagId = ((UIControl*)sender).tag;
UIButton *tempButton = (UIButton*)[scrollView viewWithTag:tagId];
NSLog(@"likeDudle: %d // %@", tagId, tempButton.titleLabel.text);
if ([tempButton.titleLabel.text isEqualToString:@"no_like"]) {
[tempButton setBackgroundImage:[UIImage imageNamed:@"icon_like_button_hit.png"] forState:UIControlStateNormal];
[tempButton setTitle:@"like" forState:UIControlStateNormal];
} else if ([tempButton.titleLabel.text isEqualToString:@"like"]) {
[tempButton setBackgroundImage:[UIImage imageNamed:@"icon_like_button.png"] forState:UIControlStateNormal];
[tempButton setTitle:@"no_like" forState:UIControlStateNormal];
}
있습니까 : 여기
내가 가진 무엇인가?
감사합니다, 당신은 10 개 이하의 이미지가있는 경우 Coulton
왜 각 버튼에 고유 한 태그를 지정하지 않습니까? – PengOne
그것은 모두 서버에서 수행되며 각 이미지는 고유 ID를 얻습니다. 각각에 대해 하나의 버튼이 있습니다. 그래서 다른 아이디를 주면 올바른 이미지와 일치하지 않을 것입니다. – iosfreak