如下图所示:
有时, 我们不想要子控件的颜色被渲染, 而是在整个点击过程中颜色都不变
如下图所示:
我们可以在自定义的cell中(继承自uitableviewcell)重写下面两个方法:
- (void)setselected:(bool)selected animated:(bool)animated
- (void)setselected:(bool)selected animated:(bool)animated
具体实现如下
- (void)setselected:(bool)selected animated:(bool)animated { // 获取 contentview 所有子控件 nsarray<__kindof uiview *> *subviews = self.contentview.subviews; // 创建颜色数组 nsmutablearray *colors = [nsmutablearray array]; for (uiview *view in subviews) { // 获取所有子控件颜色 [colors addobject:view.backgroundcolor ?: [uicolor clearcolor]]; } // 调用super [super setselected:selected animated:animated]; // 修改控件颜色 for (int i = 0; i < subviews.count; i++) { subviews[i].backgroundcolor = colors[i]; } } - (void)sethighlighted:(bool)highlighted animated:(bool)animated { // 获取 contentview 所有子控件 nsarray<__kindof uiview *> *subviews = self.contentview.subviews; // 创建颜色数组 nsmutablearray *colors = [nsmutablearray array]; for (uiview *view in subviews) { // 获取所有子控件颜色 [colors addobject:view.backgroundcolor ?: [uicolor clearcolor]]; } // 调用super [super sethighlighted:highlighted animated:animated]; // 修改控件颜色 for (int i = 0; i < subviews.count; i++) { subviews[i].backgroundcolor = colors[i]; } }
如对本文有疑问, 点击进行留言回复!!
《算法笔记上机实验指南》第4章 入门篇(2)---算法初步 5.6大整数运算
网友评论