gpt4 book ai didi

ios - 如何动态更改 UIButton 标题文本

转载 作者:行者123 更新时间:2023-11-29 02:37:37 24 4
gpt4 key购买 nike

- (void)viewDidLoad {
[self addMyButton]; // Call add button method on view load
}

- (void)addMyButton { // Method for creating button, with background image and other properties
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(aMethod)forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Show More" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 500.0, 160.0, 40.0);
[self.view addSubview:button];
}

- (void)aMethod {
NSLog(@"in load more n===>>>%d",n);
[tbl reloadData];
}

有一个 NSMutableArray 包含三十个对象。首先应该只显示 10 个对象,点击“显示更多”按钮后会显示 20 个对象,第二次点击按钮后会显示 30 个对象,按钮标题将变为“返回”。当我点击“返回”时,表格 View 应该再次只显示二十个对象。下一次单击后应显示十个元素。

最佳答案

-(void) aMethod{
if(n==2)
{
[button setTitle:@"Return" forState:UIControlStateNormal];
[button setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
[button setBackgroundColor:[UIColor orangeColor]];
// n--;
}
else
{ [button setTitle:@"Show More" forState:UIControlStateNormal];
[button setBackgroundColor:[UIColor clearColor]];
}
NSLog(@"n==>> %d",n);
[tbl reloadData];}

Here is my code.

关于ios - 如何动态更改 UIButton 标题文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26173820/

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