[英]TableView with background image
我想在表視圖后面有一個圖像,我在表視圖后面添加了一個UIImage並將表視圖背景設置為清除,在IB中它顯示了表視圖后面的圖像,但是當我運行它時,我得到了黑色背景,有人可以幫我嗎?
取下圖像並將此代碼添加到您的viewDidLoad中:
UIView *patternView = [[UIView alloc] initWithFrame:self.tableView.frame];
patternView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];
patternView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.tableView.backgroundView = patternView;
這是將固定圖像添加為表格視圖背景的方法。
或者您可以通過在主控制器類中簡單地分配tableview的backgroundView屬性來實現此操作而無需子類化...
嘗試在-(void)viewDidLoad
方法中遵循以下代碼
self.tblView= [[UITableView alloc] initWithFrame:CGRectMake(17,110, 280.0, 265) style:UITableViewStyleGrouped];
self.tblView.delegate=self;
self.tblView.dataSource=self;
//self.tblView.backgroundColor=[UIColor clearColor];
self.tblView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img3.png"]];
[self.view addSubview:self.tblView];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.