gpt4 book ai didi

ios - 如何将图像添加到 UITableViewHeaderFooterView?

转载 作者:行者123 更新时间:2023-11-28 21:53:13 26 4
gpt4 key购买 nike

谁能帮我弄清楚如何向标题 View 添加图像?我尝试使用的代码不起作用。以下是我目前所拥有的。

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
{

UITableViewHeaderFooterView *headerView = (UITableViewHeaderFooterView*)view;
if (headerView != nil)
{

headerView.contentView.backgroundColor = [UIColor greenColor];

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(200.0f, 0.0f, 100.0f, 25.0f)];

*imageView.image = [UIImageView = image.png];* //This line doesn't work.

[headerView.contentView addSubview:imageView];

UILabel *mainLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 25.0f)];
mainLabel.text = [sectionTitles objectAtIndex:section];
mainLabel.backgroundColor = [UIColor redColor];
[headerView.contentView addSubview:mainLabel];

UILabel *secondLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 26.0f, 150.0f, 20.0f)];
secondLabel.text = @"Second Label Text";

secondLabel.backgroundColor = [UIColor yellowColor];
[headerView.contentView addSubview:secondLabel];

}

}

最佳答案

请试试这个

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIImage *aImage = [UIImage imageNamed:@"myHeaderImage.png"];
UIImageView *aImgView = [[UIImageView alloc] initWithImage:aImage];
aImgView.frame = CGRectMake(5, 5, 310, 60);
return aImgView;
}

或请尝试 this , this .

关于ios - 如何将图像添加到 UITableViewHeaderFooterView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27498673/

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