更改标题视图 iOS
我四处寻找答案并想出了这段代码。我正在尝试将图片插入标题视图(通常是文字的位置)。
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 90.0)];
UIImageView *i=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"IMAGE NAME"]];
[customView addSubview:i];
return customView;
}
表视图标题保持空白。
有什么想法吗?我刚刚开始...谢谢!
I have looked around for an answer and came up with this code. I am trying to insert a picture into the header view (where words normally would be).
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 90.0)];
UIImageView *i=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"IMAGE NAME"]];
[customView addSubview:i];
return customView;
}
The table view header remains blank.
Any ideas? I'm just starting out here...Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这对我来说非常有效:
That works perfectly for me:
参考: Apple 开发者 UITableViewDelegate
返回的对象可以是 UILabel 或 UIImageView 对象,以及自定义视图。此方法仅在 tableView:heightForHeaderInSection: 也实现时才能正确工作。
尝试一下。
Reference: Apple Developer UITableViewDelegate
The returned object can be a UILabel or UIImageView object, as well as a custom view. This method only works correctly when tableView:heightForHeaderInSection: is also implemented.
Try that.
为 UIImageView 设置一个框架,例如:
i.frame = customView.frame;
set a frame for the UIImageView, eg:
i.frame = customView.frame;