国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS應用中UITableView的背景顏色與背景圖片的方法

2020-02-19 15:48:28
字體:
來源:轉載
供稿:網友

我們經常會遇到TableView設置背景圖像的問題,但如果直接設置背景視圖,就不會顯示背景圖像,因為默認情況下TableView上的單元格是不透明的,下面就讓武林技術頻道小編帶你一起來學習iOS應用中UITableView的背景顏色與背景圖片的方法吧!

改變UITableView的header、footer背景顏色

改變UITableView的header、footer背景顏色,這是個很常見的問題。之前知道的一般做法是,通過實現tableView: viewForHeaderInSection:返回一個自定義的View,里面什么都不填,只設背景顏色。但是今天發現一個更簡潔的做法:

對于iOS 6及以后的系統,實現這個新的delegate函數即可:

?

- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section {
?view.tintColor = [UIColor clearColor];
}


還可以改變文字的顏色:

?

?

?


- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section
{
?UITableViewHeaderFooterView *footer = (UITableViewHeaderFooterView *)view;
?[footer.textLabel setTextColor:[UIColor whiteColor]];
}


修改tableView的背景圖片

?

修改UITableView的背景圖片

1.圖片顯示為'PatternImage'模式。

?

// viewDidLoad

?

self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"BackgroundImage"]];

// cellForRowAtIndexPath

cell.backgroundColor = [UIColor clearColor];


這種情況下背景圖片像地板磚一樣平鋪。拉動tableView背景圖片會隨著動,若行數超過背景圖片的高度,會接著顯示下一張圖片。

?

2.正常的背景圖片。

?

// viewDidLoad

?

self.tableView.backgroundColor= [UIColor clearColor];

UIImageView*imageView = [[UIImageView alloc]initWithImage:[UIImageimage Named:@"BackgroundImage"]];

self.tableView.backgroundView = imageView;

// cellForRowAtIndexPath

cell.backgroundColor = [UIColor clearColor];


這種情況下背景圖片不會動,即無論多少行看到的都是同樣的背景。

本文是武林技術頻道小編為大家介紹的iOS應用中UITableView的背景顏色與背景圖片的方法,相信大家都了解了,希望大家可以繼續支持武林技術頻道!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阜城县| 平度市| 突泉县| 万安县| 沛县| 古田县| 南丹县| 新乐市| 来凤县| 沧州市| 彭泽县| 淅川县| 贵阳市| 平舆县| 湖南省| 二连浩特市| 黄石市| 景泰县| 集安市| 独山县| 黄平县| 渑池县| 敖汉旗| 乌鲁木齐县| 即墨市| 丰台区| 山东| 黎城县| 兴义市| 平果县| 彭泽县| 江西省| SHOW| 扬州市| 察隅县| 元氏县| 塔河县| 曲靖市| 扎囊县| 海伦市| 舞阳县|