gpt4 book ai didi

iphone - 如何通过单击按钮使textView可展开

转载 作者:行者123 更新时间:2023-11-29 03:49:50 25 4
gpt4 key购买 nike

我在 scrollView 之上有许多 textView,并且每个 textView 上面都有一个自定义按钮,以便当用户单击该 >textView 它应该展开,当它单击返回时,它应该折叠到之前的位置。

我想做的是隐藏smallTextView并在按下按钮时显示expandedTextView,当按下按钮时我想隐藏expandedtextView n 显示smallTextView。但我不知道该怎么做。任何帮助将不胜感激。

这是我的代码:

- (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:UIControlEventTouchDragInside];
[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);

}
-(void)textButtonClicked:(id)sender
{
NSLog(@"Hi");
[self.expandTextView setHidden:YES\];
NSLog(@"hey");
}

in this image every imageView has a custom button over it我如何知道哪个按钮被按下。

最佳答案

你做错了。您的方法应如下所示:

-(IBAction)textButtonClicked:(id)sender
{
NSLog(@"Hi");
[self.expandTextView setHidden:YES];
NSLog(@"hey");
}

ViewContrller 中编写此方法后,将 Expand Button 的 -touchUpInside 方法连接到 -textButtonClicked 方法。使用这一行:

[self.expandButton addTarget:self action:@selector(textButtonClicked:) forControlEvents:UIControlEventTouchUpInside];

而不是代码中的那个。

关于iphone - 如何通过单击按钮使textView可展开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17188335/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com