改變iOS應用中UITableView的背景顏色與背景圖片的方法
改變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];
這種情況下背景圖片不會動,即無論多少行看到的都是同樣的背景。
相關文章
iOS學習筆記(十六)——詳解數(shù)據(jù)庫操作(使用FMDB)
這篇文章主要介紹了iOS學習筆記(十六)——詳解數(shù)據(jù)庫操作(使用FMDB),具有一定的參考價值,有興趣的可以了解一下。2016-12-12iOS開發(fā)中CAlayer層的屬性以及自定義層的方法
這篇文章主要介紹了iOS開發(fā)中CAlayer層的屬性以及自定義層的方法,代碼基于傳統(tǒng)的Objective-C,需要的朋友可以參考下2015-11-11