0
레이블 루프에서 어떤 레이블을 두드려면 어떻게 얻을 수 있습니까? 나는 루프에 4 개의 레이블이 있고 나는 그 태그가 3 인 레이블을 클릭하면 다른 레이블이 이미 숨겨져있는보기에 나타나야한다. 어떻게 얻을 수 있는가?대물 렌즈 C에서 사용자 탭 제스처를 사용하여 레이블 태그를 얻는 방법
CGFloat y1 = 100.0;
CGFloat x1 = 30.0;
CGRect rect1 = CGRectMake(x1, y1, 100, 30);
for (int i = 0; i < 4; i++)
{
label = [[UILabel alloc] initWithFrame:rect1];
label.tag = 4+i;
label.textAlignment = NSTextAlignmentCenter;
label.backgroundColor = [UIColor blueColor];
label.textColor = [UIColor whiteColor];
label.font = [UIFont fontWithName:@"Verdana-Bold" size:17.0];
label.text = @"Hello";
label.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gotTapped:)];
[label addGestureRecognizer:tap];
[self.view addSubview:label];
label2 = [[UILabel alloc] initWithFrame:CGRectMake(200, y1, 50, 30)];
label2.tag = 100+i;
label2.textAlignment = NSTextAlignmentCenter;
label2.backgroundColor = [UIColor yellowColor];
label2.textColor = [UIColor whiteColor];
label2.font = [UIFont fontWithName:@"Verdana-Bold" size:17.0];
label2.text = @"World";
label2.hidden = YES;
[self.view addSubview:label2];
rect1.origin.y += 45;
}
}
-(void)gotTapped:(UITapGestureRecognizer*)sender {
for (UILabel *v in label2) {
v.hidden = !v.hidden;
switch(((UITapGestureRecognizer *)sender).view.tag)
{
case 1:
NSLog(@"Clicked on label 1");
break;
case 2:
NSLog(@"Clicked on label 2");
break;
}
클릭했지만 태그를 사용하여 레이블을 클릭 할 때 숨겨진 레이블을 가져 오려면 어떻게해야합니까? – Alex
당신은 내 숨겨진 레이블에 대한 귀하의 답변을 업데이트하시기 바랍니다 다음 받아 들일 것이고 upvote 감사합니다 수 있습니다. – Alex
처음에는 label2가 숨겨져 있습니다. – Alex