0

私はtextViews上にたくさんあり、その上にカスタムボタンがあり、ユーザーがクリックすると展開し、クリックすると前の位置に折りたたまれますscrollViewtextViewtextView

私が考えているのは、ボタンが押されsmallTextViewたときに非表示にして表示し、ボタンが押されたときに非表示にして表示することです。しかし、どうすればいいのかわかりません。どんな助けでも大歓迎です。expandedTextViewexpandedtextViewsmallTextView

これが私のコードです:

-

 (void)viewDidLoad
        {
            [super viewDidLoad];
            // Do any additional setup after loading the view from its nib.

            self.title = @"Demo";
            appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
            for (int i=0;i<[appDelegate.serverResponseArray count];i++)
            {
            self.expandTextView = [[UITextView alloc] init];
            [self.expandTextView setFrame:CGRectMake(8.0f, i*50.0f+10.0f, 270.0f, 40.0f)];
            [self.expandTextView setBackgroundColor:[UIColor grayColor]];
            [self.expandTextView setFont:[UIFont fontWithName:@"helvetica" size:12]];
            [self.expandTextView setText:@"Welcome!!!"];
            [self.expandTextView setTextColor:[UIColor colorWithRed:255.0f/255.0f green:255.0f/255.0f blue:255.0f/255.0f alpha:1]];
            [self.expandTextView setUserInteractionEnabled:NO];
            [self.scrollView addSubview:self.expandTextView];
            self.expandTextView = nil;

            self.expandButton = [[UIButton alloc]initWithFrame:CGRectMake(8.0f, i*50.0f+1.0f, 270.0f, 60.0f)];
            [self.expandButton setBackgroundColor:[UIColor clearColor]];
            [self.expandButton addTarget:self action:@selector(textButtonClicked:) forControlEvents:UIControlEventTouchUpInside];

self.expandButton.tag = i;
            [self.scrollView addSubview:self.expandButton];

            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(278.0f, i*50.0f+10.0f, 14.0f, 40.0f)];
            [imageView setBackgroundColor:[UIColor grayColor]];
            [imageView setImage:[UIImage imageNamed:@"arrow.png"]];
            [self.scrollView addSubview:imageView];
            imageView = nil;

        }


        float maxHeight = 0;

            for(UIView *v in [self.scrollView subviews])
            {
                if(v.frame.origin.x + v.frame.size.height > maxHeight)
                    maxHeight = v.frame.origin.x + v.frame.size.height;
            }

            self.scrollView.contentSize = CGSizeMake(_scrollView.frame.size.width, maxHeight+2570);

        }
        -(IBAction)textButtonClicked:(id)sender
        {
             NSLog(@"%@",sender);
        }

この画像では、すべてのimageViewにカスタムボタンがあります また、どのボタンが押されているかを知るにはどうすればよいですか。

4

3 に答える 3

0

どのボタンが押されたかを知るには、タグ値をボタンに割り当てる必要があります

-(IBAction)textButtonClicked:(id)sender
{
    UIButton *btn=(UIButton*)sender;

    NSLog(@"Tag of button = %d",btn.tag);
}  

そして、他の画像ビュー(非表示と表示)を使用する代わりに、既存のimageViewのフレームを変更することをお勧めします

于 2013-06-19T10:55:40.470 に答える