[英]unable to set tableview background & label background as same color?
[英]Set Tableview background with Image and Label
我到處搜索,但是找不到適合我的答案。 我只想在tableview中沒有任何項目的情況下,在tableview背景中設置一個Image和一個Text。 像這樣:
http://i.stack.imgur.com/7DZa5.png
它還必須位於中心,並且必須在iPhone和iPad上均可使用。
我嘗試將tableview背景設置為ImageView,但無法將標簽放置在圖像下方。 我也曾嘗試為此創建一個單獨的.xib文件,但無法使其正常工作。 請幫忙!
你信不信魔術 ? 開玩笑...
我相信它不是表格視圖的背景。 每當填充您的表格視圖的數組不包含數據時,您都需要刪除表格視圖(_tableView.hidden = YES;將工作),並使用您的圖像和標簽添加此自定義視圖。
為什么不將UITableView
的background
屬性設置為clear。 然后只是將圖像設置為自己的view
背景? 使用自動AutoLayout
將幫助您AutoLayout
保持其居中狀態。
它為你工作
1> IBOutlet lblTextlable
和imgNoItem
2>將UITableView的background屬性設置為clear。
- (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;
謝謝
正如我在該圖像中看到的,它是標簽和圖像。 因此,代碼邏輯可能如下:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.