当前位置: 移动技术网 > IT编程>移动开发>IOS > 改变iOS应用中UITableView的背景颜色与背景图片的方法

改变iOS应用中UITableView的背景颜色与背景图片的方法

2019年07月24日  | 移动技术网IT编程  | 我要评论

免费送q币,广工,荒村红杏免费阅读

改变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];


这种情况下背景图片不会动,即无论多少行看到的都是同样的背景。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网