IOS自定义UITableViewCell的高亮背景色
2015-07-22 13:59
453 查看
IOS的sdk中,对UITableViewCell的高亮背景色只支持两种颜色,分别为UITableViewCellSelectionStyleBlue和UITableViewCellSelectionStyleGray。 那么如何自定义这个颜色呢。一个思路是当用户点下cell时设置你想要的cell的背景色,当释放点击时给cell重新设回原来的背景色,这样就能达到预想的效果了。 下面是具体实现的代码: -(void)drawRect:(CGRect)rect { if (self.highlighted) { self.backgroundColor = [UIColor colorWithHexString:@"0x383838"]; }else{ self.backgroundColor = [UIColor clearColor]; } } - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated { [super setHighlighted:highlighted animated:animated]; [self setNeedsDisplay]; } 1. 继承UITableViewCell 2. 重写以上两个方法。 当每次用户点击或者释放的时候,系统都会来调用下面这个方法,从而来改变cell的高亮背景色。
相关文章推荐
- UIView属性clipsToBounds的使用
- AutoLayout一、UILabel的高度自适应
- The resource identified by this request is only capable of generating responses with characteristics
- Codeforces Round #279 (Div. 2) B. Queue 模拟
- android <viewStub />, <requestFocus />, <merge /> and <include />用法
- hdu 5288 OO’s Sequence 枚举因数
- 【UIKit】-10-UIAlertView - iOS 8 之后弃用,改用 UIAlertViewController
- iOS编程第四版第12,13章---Touch Events and UIResponder, UIGestureRecognizer and UIMenuController
- UILocalNotification 的使用
- 【UIKit】-9-UIAlertController - IOS8 包括 alert 和 sheet
- 【UIkit】-8-UIActionSheet - 底部弹出提示,快要被取代
- 思维题 HDOJ 5288 OO’s Sequence
- [tableView reloadData]方法添加动画的方法
- C#使用队列(Queue)解决简单的并发问题
- 使用Arduino与A4988 驱动步进电机
- Android异步处理三:Handler+Looper+MessageQueue深入详解
- Android异步处理二:使用AsyncTask异步更新UI界面
- Android异步处理一:使用Thread+Handler实现非UI线程更新UI界面
- easy-ui
- zoj 1649 Rescue bfs