欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2016年03月29日 14:47:15   作者:ForeverYoung21  
這篇文章主要介紹了改變iOS應用中UITableView的背景顏色與背景圖片的方法,將UITableView的header、footer設成clearColor時要注意實際效果是否真的變透明,需要的朋友可以參考下

改變UITableView的header、footer背景顏色

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

對于iOS 6及以后的系統(tǒng),實現(xiàn)這個新的delegate函數(shù)即可:

復制代碼 代碼如下:

- (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背景圖片會隨著動,若行數(shù)超過背景圖片的高度,會接著顯示下一張圖片。

2.正常的背景圖片。

復制代碼 代碼如下:

// viewDidLoad

self.tableView.backgroundColor= [UIColor clearColor];

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

self.tableView.backgroundView = imageView;

// cellForRowAtIndexPath

cell.backgroundColor = [UIColor clearColor];


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

相關文章

最新評論