使用图像和标签设置 Tableview 背景
Set Tableview background with Image and Label
我搜索了所有地方,但没有找到适合我的答案。
当表格视图中没有项目时,我只想在图像下方设置表格视图背景和图像。像这样:
http://i.stack.imgur.com/7DZa5.png
它也必须在中心并且必须在 iPhone 和 IPad 中工作。
我已经尝试将 tableview 背景设置为 ImageView,但我无法将标签定位在图像下方。我也试过为此创建一个单独的 .xib 文件,但我无法让它工作。请帮忙!
你相信魔法吗?开玩笑...
我相信这不是 table 视图的背景。每当填充 table 视图的数组不包含任何数据时,您需要删除 table 视图(_tableView.hidden = 是;将起作用)并添加带有图像和标签的自定义视图。
你为什么不设置 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;
}
您好,我已经使用 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;
谢谢
正如我在该图像中看到的那样,它是标签和图像。所以代码逻辑可能如下:
- 如果列表视图中没有项目,隐藏它和"show"图像/标签。
- 如果列表视图中至少有一项,则显示列表视图并隐藏图像/标签。
我搜索了所有地方,但没有找到适合我的答案。 当表格视图中没有项目时,我只想在图像下方设置表格视图背景和图像。像这样:
http://i.stack.imgur.com/7DZa5.png
它也必须在中心并且必须在 iPhone 和 IPad 中工作。
我已经尝试将 tableview 背景设置为 ImageView,但我无法将标签定位在图像下方。我也试过为此创建一个单独的 .xib 文件,但我无法让它工作。请帮忙!
你相信魔法吗?开玩笑...
我相信这不是 table 视图的背景。每当填充 table 视图的数组不包含任何数据时,您需要删除 table 视图(_tableView.hidden = 是;将起作用)并添加带有图像和标签的自定义视图。
你为什么不设置 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;
}
您好,我已经使用 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;
谢谢
正如我在该图像中看到的那样,它是标签和图像。所以代码逻辑可能如下:
- 如果列表视图中没有项目,隐藏它和"show"图像/标签。
- 如果列表视图中至少有一项,则显示列表视图并隐藏图像/标签。