最近有做一个tableView的编辑事件(删除) ,编辑事件其实不难,我是在
- (NSArray*)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath代理方法中实现的, 功能好实现 ,就是滑动出现删除按钮的时候,删除按钮的UI跟要求的不符合,系统默认的是红色背景 白色字体颜色,如图所示:

可是我们UI要求是白色背景,字体为黑色,然后设置了UITableViewRowAction的背景,这里直接拿我工程的代码来做示例了:

可是在设置action字体颜色时发现并没有titleColor这个属性,

然后在网上找了许多方法,均没有实现效果,最后在stackoverflow找到一个方法可以设置:

效果为:

这个方法就是设置UIButton类的外观,但是这个有一个问题就是设置之后工程里面所有的按钮的字体颜色都会改变,可是我想要的只是在当前页面的颜色改变,不需影响其他页面的按钮,这样的话该方法显然就不适合了,最后在查看官方文档的时候发现一个方法:
+ (instancetype)appearanceWhenContainedInInstancesOfClasses:(NSArray> *)containerTypes NS_AVAILABLE_IOS(9_0);
在改变按钮外观的时候设置是改变的哪个类的外观,这样就能满足我们的要求了,
最后代码如下:

效果:

这样的话就实现了改变按钮的样式,也不会影响其他页面的按钮。
如果大家有什么其他方法的话请不吝赐教..
最后如果能帮到大家就点个喜欢吧,*_*
网友评论