我已经遍寻搜索,但还没有找到适合我的答案。 我只想在桌面视图中没有项目的情况下,使用图像和图像下方的文本设置桌面背景。就像这样:设置带有图像和标签的Tableview背景
http://i.stack.imgur.com/7DZa5.png
它也必须是在该中心,并在iPhone和iPad上运行。
我曾尝试将tableview背景设置为ImageView,但无法将标签放置在图像下方。我也曾尝试为此创建一个单独的.xib文件,但我无法使其工作。请帮忙!
我已经遍寻搜索,但还没有找到适合我的答案。 我只想在桌面视图中没有项目的情况下,使用图像和图像下方的文本设置桌面背景。就像这样:设置带有图像和标签的Tableview背景
http://i.stack.imgur.com/7DZa5.png
它也必须是在该中心,并在iPhone和iPad上运行。
我曾尝试将tableview背景设置为ImageView,但无法将标签放置在图像下方。我也曾尝试为此创建一个单独的.xib文件,但我无法使其工作。请帮忙!
您好我已经使用ImageView并在imageview中设置了一个标签。然后添加imageview作为tableview的背景。它适用于iphone和ipad。这里是代码:
UIImage *image = [UIImage imageNamed:@"ico_file_list_not_found.png"];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
imageView.image = image;
[imageView setContentMode:UIViewContentModeCenter];
UILabel *messageLbl = [[UILabel alloc] initWithFrame:CGRectMake(self.tableView.bounds.size.width/2 - image.size.width/2 + (image.size.width/7),
self.tableView.bounds.size.height/2 + image.size.height/2
, 120, 21)];
messageLbl.text = @"No files found.";
[imageView addSubview:messageLbl];
self.tableView.backgroundView = imageView;
谢谢
你相信魔法吗?开玩笑...
我相信它不是表格视图的背景。每当填充表格视图的数组不包含数据时,您需要删除表格视图(_tableView.hidden = YES;将工作),并添加此自定义视图与您的图像和标签。
为什么不设置UITableView
的background
属性来清除。那么只需将图像设置为view
它的背景呢?使用AutoLayout
将帮助您随时保持中心位置。
它为你工作
1>IBOutlet lblTextlable
和imgNoItem
2>你设置的UITableView的背景属性清除。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
if (arrTableListItem.count==0) {
lblTextlable.hidden = false;
imgNoItem.hidden = false;
}
else {
lblTextlable.hidden = true;
imgNoItem.hidden = true;
}
return arrTableListItem.count;
}
当我看到图像,它的标签和图像。所以代码逻辑如下: