gpt4 book ai didi

ios - 如何更改添加到 TableView 部分标题的按钮图像

转载 作者:行者123 更新时间:2023-12-01 18:22:59 24 4
gpt4 key购买 nike

我在部分标题中添加了一个按钮,该按钮显示单击它的 View 。我的需要是在显示 View 时显示“向上箭头”图像,在隐藏 View 时显示“向下箭头”图像。

我怎样才能做到这一点?请帮我 ...

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(0, 0, 316, 60)];
[btn setTag:section];
[aView addSubview:btn];
[btn addTarget:self action:@selector(sectionTapped:) forControlEvents:UIControlEventTouchDown];
btn.backgroundColor=[UIColor clearColor];

}

最佳答案

我建议您可以使用 2 张图片 - 1 张用于“向上”箭头,1 张用于“向下”箭头。
将默认图像设置为状态 UIControlStateNormal 的 btn,并将其他图像设置为状态 UIControlStateSelected。
现在在您的 sectionTapped: 方法中只需更改按钮的状态。
因此,当您显示或隐藏 View 时,您需要将按钮设置为选择是/否。

希望这可以帮助。

关于ios - 如何更改添加到 TableView 部分标题的按钮图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16229910/

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