UI学习第08天
2016-03-09 17:55
302 查看
最近一段时间自己的学习状态真的很差,甚至到了一度想要放弃iOS学习的想法,因为一件事你长期坚持做了下去但是一直没有达到你想要的效果,难免会感到沮丧或者是懈怠有时候真的很想放弃,但心里又不甘心,自己投入了这么多的精力去做的事儿,不能就此荒废。这段时间各种事情在困扰着我,回家过年耽误了半个月的时间,回来上班快一个月了这一个月的时间里,每天都是一副要死不活的样子,想法很多,但是依然只能坐在这方寸之地做着一些没有意义,没有营养,甚至是枯燥无味的生活。为了达到我元旦那天晚上立下的目标,我决心要改变现在的这个僵局,改变这种每天不温不火的状态,我一定要改变,而且要快。
2016年留给我的时间不多了,今天已经是3月9号了,马上一年的四分之一就过去了。晚上躺在床上的时候我心里在问自己,这个月过完你所立下的目标完成了四分之一吗?难道还能只像学生时代那样对自己的承诺只是当个屁在放?过了今年的五月份我就已经是年满22周岁的青年了,早已不再是一个单纯,幼稚,对未来充满着意淫的糊涂虫,古人说年满二十即加冠,亦慕圣贤之道,霍去病在我这个年纪就已经是名满天下的大司马,被封侯拜相,供人敬仰了。我不求跟这种大气魄,大毅力的人相比,只求能够通过自己的勤奋,刻苦获得自己想要的生活方式,实现自己的一些目标而已。但是如今以现在的状态来看真的是所差甚远,你真的要努力。
学习是一件长期不间断坚持的事情,只有持之以恒才能有所收获,看你学习的这九个月的时间里,有很多时间都间断了学习,三天打鱼两天晒这种做法百害而无一益,外人看你好似勤奋刻苦,可是真相只有你自己知道。
坚持,不断坚持。
第08天学习笔记:
1、懒加载代码复习
model中封装字典转模型,加载plist文件
+ (NSArray *)messagesList
{
//读取plist
NSString *path = [[NSBundle
mainBundle] pathForResource:@"messages"
ofType:@"plist"];
NSArray *dicArray = [NSArray
arrayWithContentsOfFile:path];
//字典转模型
NSMutableArray *tmpArray = [NSMutableArray
array];
//上一条消息
CZMessage *preMessage;
for (NSDictionary *dic
in dicArray) {
CZMessage *message = [CZMessage
messageWithDic:dic];
//获取上一条消息
// preMessage = [tmpArray lastObject];
if ([message.time
isEqualToString:preMessage.time]) {
//时间相等
隐藏
message.hiddenTime =
YES;
}
[tmpArray addObject:message];
//获取上一条消息
preMessage = message;
}
return tmpArray;
}
controller中进行懒加载:
//1 懒加载
- (NSArray *)messageFrames
{
if (_messageFrames ==
nil) {
//1.1
加载模型数据
NSArray *messages = [CZMessage
messagesList];
NSMutableArray *tmpArray = [NSMutableArray
array];
//1.2
创建frame模型
for (CZMessage *msg
in messages) {
CZMessageFrame *msgFrame = [[CZMessageFrame
alloc] init];
msgFrame.message = msg;
[tmpArray addObject:msgFrame];
}
_messageFrames = tmpArray;
}
return
_messageFrames;
}
2、零散代码
//去掉分割线
self.tableView.separatorStyle
= UITableViewCellSeparatorStyleNone;
//不能选中
self.tableView.allowsSelection =
NO;
//背景颜色
// self.tableView.backgroundColor = [UIColor lightGrayColor];
self.tableView.backgroundColor
= [UIColor
colorWithRed:240/255.0
green:240/255.0
blue:240/255.0
alpha:1];
//全0
黑色
全255 白色
// self.tableView.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:0/255.0 alpha:1];
3、数据源方法复习:
返回有几组,默认是1
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
返回有几行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
返回每一行的cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
4、tableView代理方法复习:
返回行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
返回header的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
返回footer的高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;
5、重写属性的set方法时第一步一定时给属性重新赋值:
- (void)setMessage:(CZMessage *)message
{
_message = message;
//获取屏幕的宽度
UIScreen *screen = [UIScreen
mainScreen];
CGFloat margin =
10;
//时间的frame
CGFloat timeW = screen.bounds.size.width;
CGFloat timeH =
40;
CGFloat timeX =
0;
CGFloat timeY =
0;
if (!message.isHiddenTime) {
_timeFrame =
CGRectMake(timeX, timeY, timeW, timeH);
}
6、计算文本大小用到的自定义方法示范:
// 计算文本的大小
- (CGSize)sizeWithText:(NSString *)text maxSize:(CGSize)maxSize fontSize:(CGFloat)fontSize
{
return [text
boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName:[UIFont
systemFontOfSize:fontSize]}
context:nil].size;
}
7、设置QQ聊天背景图片的代码示范:
//设置消息的背景图片
if (msg.type ==
CZMessageTypeSelf) {
// [bgImage resizableImageWithCapInsets:<#(UIEdgeInsets)#>]
// [bgImage resizableImageWithCapInsets:<#(UIEdgeInsets)#> resizingMode:(UIImageResizingMode)]
[self.textView
setBackgroundImage:[UIImage
resizeImage:@"chat_send_nor"]
forState:UIControlStateNormal];
[self.textView
setBackgroundImage:[UIImage
resizeImage:@"chat_send_press_pic"]
forState:UIControlStateHighlighted];
}else{
[self.textView
setBackgroundImage:[UIImage
resizeImage:@"chat_recive_nor"]
forState:UIControlStateNormal];
[self.textView
setBackgroundImage:[UIImage
resizeImage:@"chat_recive_press_pic"]
forState:UIControlStateHighlighted];
}
8、图片的缩放代码示范:
//缩放图片(平铺)
- (UIImage *)resizeImage:(NSString *)imgName
{
UIImage *bgImage = [UIImage
imageNamed:imgName];
//缩放图片
bgImage = [bgImage stretchableImageWithLeftCapWidth:bgImage.size.width /
2 topCapHeight:bgImage.size.height /
2];
return bgImage;
}
2016年留给我的时间不多了,今天已经是3月9号了,马上一年的四分之一就过去了。晚上躺在床上的时候我心里在问自己,这个月过完你所立下的目标完成了四分之一吗?难道还能只像学生时代那样对自己的承诺只是当个屁在放?过了今年的五月份我就已经是年满22周岁的青年了,早已不再是一个单纯,幼稚,对未来充满着意淫的糊涂虫,古人说年满二十即加冠,亦慕圣贤之道,霍去病在我这个年纪就已经是名满天下的大司马,被封侯拜相,供人敬仰了。我不求跟这种大气魄,大毅力的人相比,只求能够通过自己的勤奋,刻苦获得自己想要的生活方式,实现自己的一些目标而已。但是如今以现在的状态来看真的是所差甚远,你真的要努力。
学习是一件长期不间断坚持的事情,只有持之以恒才能有所收获,看你学习的这九个月的时间里,有很多时间都间断了学习,三天打鱼两天晒这种做法百害而无一益,外人看你好似勤奋刻苦,可是真相只有你自己知道。
坚持,不断坚持。
第08天学习笔记:
1、懒加载代码复习
model中封装字典转模型,加载plist文件
+ (NSArray *)messagesList
{
//读取plist
NSString *path = [[NSBundle
mainBundle] pathForResource:@"messages"
ofType:@"plist"];
NSArray *dicArray = [NSArray
arrayWithContentsOfFile:path];
//字典转模型
NSMutableArray *tmpArray = [NSMutableArray
array];
//上一条消息
CZMessage *preMessage;
for (NSDictionary *dic
in dicArray) {
CZMessage *message = [CZMessage
messageWithDic:dic];
//获取上一条消息
// preMessage = [tmpArray lastObject];
if ([message.time
isEqualToString:preMessage.time]) {
//时间相等
隐藏
message.hiddenTime =
YES;
}
[tmpArray addObject:message];
//获取上一条消息
preMessage = message;
}
return tmpArray;
}
controller中进行懒加载:
//1 懒加载
- (NSArray *)messageFrames
{
if (_messageFrames ==
nil) {
//1.1
加载模型数据
NSArray *messages = [CZMessage
messagesList];
NSMutableArray *tmpArray = [NSMutableArray
array];
//1.2
创建frame模型
for (CZMessage *msg
in messages) {
CZMessageFrame *msgFrame = [[CZMessageFrame
alloc] init];
msgFrame.message = msg;
[tmpArray addObject:msgFrame];
}
_messageFrames = tmpArray;
}
return
_messageFrames;
}
2、零散代码
//去掉分割线
self.tableView.separatorStyle
= UITableViewCellSeparatorStyleNone;
//不能选中
self.tableView.allowsSelection =
NO;
//背景颜色
// self.tableView.backgroundColor = [UIColor lightGrayColor];
self.tableView.backgroundColor
= [UIColor
colorWithRed:240/255.0
green:240/255.0
blue:240/255.0
alpha:1];
//全0
黑色
全255 白色
// self.tableView.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:0/255.0 alpha:1];
3、数据源方法复习:
返回有几组,默认是1
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
返回有几行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
返回每一行的cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
4、tableView代理方法复习:
返回行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
返回header的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
返回footer的高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;
5、重写属性的set方法时第一步一定时给属性重新赋值:
- (void)setMessage:(CZMessage *)message
{
_message = message;
//获取屏幕的宽度
UIScreen *screen = [UIScreen
mainScreen];
CGFloat margin =
10;
//时间的frame
CGFloat timeW = screen.bounds.size.width;
CGFloat timeH =
40;
CGFloat timeX =
0;
CGFloat timeY =
0;
if (!message.isHiddenTime) {
_timeFrame =
CGRectMake(timeX, timeY, timeW, timeH);
}
6、计算文本大小用到的自定义方法示范:
// 计算文本的大小
- (CGSize)sizeWithText:(NSString *)text maxSize:(CGSize)maxSize fontSize:(CGFloat)fontSize
{
return [text
boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName:[UIFont
systemFontOfSize:fontSize]}
context:nil].size;
}
7、设置QQ聊天背景图片的代码示范:
//设置消息的背景图片
if (msg.type ==
CZMessageTypeSelf) {
// [bgImage resizableImageWithCapInsets:<#(UIEdgeInsets)#>]
// [bgImage resizableImageWithCapInsets:<#(UIEdgeInsets)#> resizingMode:(UIImageResizingMode)]
[self.textView
setBackgroundImage:[UIImage
resizeImage:@"chat_send_nor"]
forState:UIControlStateNormal];
[self.textView
setBackgroundImage:[UIImage
resizeImage:@"chat_send_press_pic"]
forState:UIControlStateHighlighted];
}else{
[self.textView
setBackgroundImage:[UIImage
resizeImage:@"chat_recive_nor"]
forState:UIControlStateNormal];
[self.textView
setBackgroundImage:[UIImage
resizeImage:@"chat_recive_press_pic"]
forState:UIControlStateHighlighted];
}
8、图片的缩放代码示范:
//缩放图片(平铺)
- (UIImage *)resizeImage:(NSString *)imgName
{
UIImage *bgImage = [UIImage
imageNamed:imgName];
//缩放图片
bgImage = [bgImage stretchableImageWithLeftCapWidth:bgImage.size.width /
2 topCapHeight:bgImage.size.height /
2];
return bgImage;
}
相关文章推荐
- 让build自动增长的脚本
- iOS 9人机界面指南(四):UI元素
- 修改UItextField输入框placeholder的字体默认颜色和大小,采用KVC方式设置
- iOS个人整理24-集合视图--UICollectionView
- Algrothm_Sort_QuickSort
- 创建sequence
- iosUI篇-Date Picker 和 UITool Bar 控件简单的介绍
- Java集合类: Set、List、Map、Queue使用场景梳理
- 设置继承自UIScrollView控件的滚动速度
- iOS 【UIKit-UIImageView 的 contentMode 属性概述】
- Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag
- Android中Volley的Request的自定义
- 数据库连接池 druid配置 (阿里)
- CSRF verification failed. Request aborted.
- easyUI中datetimebox和combobox的取值方法
- NSOperationQueue
- Android酷炫实用的开源框架(UI框架)
- easyUI参数传递Long型8100131457085857579980953变成8.100131457085857e 24的问题,如下可以解决
- QueryPerformanceFrequency使用方法--Windows高精度定时计数
- alibaba/druid 使用ConfigFilter