[英]Setting the background image for the UITableView eats memory and freezes the app
[英]Setting background Image to uitableview?
我想將圖像設置為我的uitableview
的背景。 這是我正在使用的代碼:
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background_tableview.png"]];
這顯示了正確的圖像,但是一旦填充了表格,就會發生一些奇怪的事情。 部分圖像顯示在每個tableviewcell
中,並且圖像隨着表格滾動。 如何使圖像保持固定並且每個tableviewcell
不顯示圖像的一部分?
謝謝,
TC
如果您不想滾動,您不想設置UITableView
的背景。 相反,您希望將UITableView
的背景設置為透明 - 並在UITableView
后面提供您自己的固定背景。
為此,首先將 UITableView 的背景設置為“清除顏色”。
以編程方式: self.tableView.backgroundColor = [UIColor clearColor];
您還需要取消選中不透明復選框。
以編程方式: self.tableView.opaque = NO;
在UITableView
后面的視圖中設置您想要的固定背景。
確保您的任何UITableViewCell
中的任何子視圖也是backgroundColor = [UIColor clearColor];
( UITextView
等)
TableView 背景的圖像
self.tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"your_image"]];
不要忘記用圖像類型寫文件名。 例子:
self.tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myPhoto.png"]];
/* 在 uitableview 中設置 Backgroundimage 如下*/
UIImageView *imguser = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"user"]];
[tblUser setBackgroundView:imguser];
如果在UIViewController
內部添加tableView
和Imageview
在代碼中,創建tableView
的出口並將其連接到 xib 中的tableView
,將視圖連接到UIView
將圖像放入UIImageView
並單擊imageView
。 Select:
編輯器>排列>發送到后面
在UIViewController
的viewDidLoad
方法中,添加以下行:
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.opaque = NO;
它對我有用:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.