国产探花免费观看_亚洲丰满少妇自慰呻吟_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的背景顏色與背景圖片的方法,相信大家都了解了,希望大家可以繼續支持武林技術頻道!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 仙桃市| 明星| 桐城市| 鹿邑县| 黑龙江省| 疏勒县| 宜兰县| 顺义区| 齐齐哈尔市| 喀喇沁旗| 金湖县| 台南市| 桑日县| 兖州市| 明光市| 苗栗县| 交城县| 永兴县| 邯郸县| 高唐县| 奎屯市| 津南区| 大足县| 甘孜| 景泰县| 绥棱县| 河曲县| 定边县| 古蔺县| 桂平市| 卢龙县| 南澳县| 兴和县| 连平县| 皮山县| 开封县| 庆元县| 清水河县| 巩留县| 岳池县| 弥渡县|