我已經遍尋搜索,但還沒有找到適合我的答案。 我只想在桌面視圖中沒有項目的情況下,使用圖像和圖像下方的文本設置桌面背景。就像這樣:設置帶有圖像和標籤的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;
}
當我看到圖像,它的標籤和圖像。所以代碼邏輯如下: