平时小积累
2015-11-01 13:32
190 查看
一:使用多线程来处理数据的存储
二:自定义cell里面实现重用机制,textLabel调
textLabel可以调整位置的,只要自定义cell然后实现layoutSubviews方法,重新设置大小即可,而且在初始化方法里进行相关属性的设置。那么相应的detailTextLabel和图片子控件都是可以调节的,全部重新设置frame.
重新布局子视图
三:类方法中调用实例化方法只要初始化一个对象即可, ok!
// 需要将照片保存至应用程序沙箱,由于涉及到数据存储,同时与界面无关,可以使用多线程来保存图像 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // 保存图像 // 1. 去图像路径 NSArray *docs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *imagePath = [docs[0]stringByAppendingPathComponent:@"abc.png"]; // 2. 转换成NSData保存 NSData *imageData = UIImagePNGRepresentation(image); [imageData writeToFile:imagePath atomically:YES]; });
二:自定义cell里面实现重用机制,textLabel调
在自定义cell里面实现重用机制,这样看起来更容易 + (instancetype)cellWithTableView:(UITableView *)tableView { static NSString *ID = @"lrc"; HMLrcCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; if (cell == nil) { cell = [[HMLrcCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID]; } return cell; }
textLabel可以调整位置的,只要自定义cell然后实现layoutSubviews方法,重新设置大小即可,而且在初始化方法里进行相关属性的设置。那么相应的detailTextLabel和图片子控件都是可以调节的,全部重新设置frame.
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.backgroundColor = [UIColor clearColor];//只要设置了cell的背景颜色和tableView的背景颜色为clearColor,那么就是透明的。 self.selectionStyle = UITableViewCellSelectionStyleNone; self.textLabel.textColor = [UIColor whiteColor]; self.textLabel.numberOfLines = 0; self.textLabel.textAlignment = NSTextAlignmentCenter; } return self; }
重新布局子视图
- (void)layoutSubviews { [super layoutSubviews]; self.textLabel.frame = self.bounds; }
三:类方法中调用实例化方法只要初始化一个对象即可, ok!
+ (instancetype)heroWithDict:(NSDictionary *)dict { return [[self alloc] initWithDict:dict]; } - (instancetype)initWithDict:(NSDictionary *)dict { if (self = [super init]) { [self setValuesForKeysWithDictionary:dict]; } return self; }
相关文章推荐
- ZOJ 2971-G - Give Me the Number-模拟
- No.3 Add Digits (digital root)
- web开发 http生产者、消费者请求限定(跟着开涛学SpringMVC)
- vi 编辑内容中查找字符位置
- 单点登录和单点登出CAS的使用
- hudu 1050 sort oj上的易错点 贪心算法
- 在javaweb中添加过滤器
- No.2 flip game 翻转游戏
- cf#328-B. The Monster and the Squirrel-水题+数学规律
- Shiro使用和源码分析---3
- 另一种导致的原因:java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/
- 【学习笔记0001】Go初学者需要关注的50个注意事项
- Intel- 64 与 IA-32架构软件开发人员手册 中文版
- Android SDK安装更新——Failed to fetch URL http://dl-ssl.google.com/android/repository/a
- No.1 Nim Game 取物游戏
- LightOJ - 1407 Explosion(2-SAT)
- 笛卡尔 变数
- SVN创建版本库
- LeetCode Excel Sheet Column Title
- 数字图像处理2--数学基础(傅立叶,拉普拉斯,卷积,差分计算)