UI学习第08天

来源:互联网 发布:vscode great icons 编辑:程序博客网 时间:2024/05/24 05:55

  最近一段时间自己的学习状态真的很差,甚至到了一度想要放弃iOS学习的想法,因为一件事你长期坚持做了下去但是一直没有达到你想要的效果,难免会感到沮丧或者是懈怠有时候真的很想放弃,但心里又不甘心,自己投入了这么多的精力去做的事儿,不能就此荒废。这段时间各种事情在困扰着我,回家过年耽误了半个月的时间,回来上班快一个月了这一个月的时间里,每天都是一副要死不活的样子,想法很多,但是依然只能坐在这方寸之地做着一些没有意义,没有营养,甚至是枯燥无味的生活。为了达到我元旦那天晚上立下的目标,我决心要改变现在的这个僵局,改变这种每天不温不火的状态,我一定要改变,而且要快。

  2016年留给我的时间不多了,今天已经是3月9号了,马上一年的四分之一就过去了。晚上躺在床上的时候我心里在问自己,这个月过完你所立下的目标完成了四分之一吗?难道还能只像学生时代那样对自己的承诺只是当个屁在放?过了今年的五月份我就已经是年满22周岁的青年了,早已不再是一个单纯,幼稚,对未来充满着意淫的糊涂虫,古人说年满二十即加冠,亦慕圣贤之道,霍去病在我这个年纪就已经是名满天下的大司马,被封侯拜相,供人敬仰了。我不求跟这种大气魄,大毅力的人相比,只求能够通过自己的勤奋,刻苦获得自己想要的生活方式,实现自己的一些目标而已。但是如今以现在的状态来看真的是所差甚远,你真的要努力。

  学习是一件长期不间断坚持的事情,只有持之以恒才能有所收获,看你学习的这九个月的时间里,有很多时间都间断了学习,三天打鱼两天晒这种做法百害而无一益,外人看你好似勤奋刻苦,可是真相只有你自己知道。

  坚持,不断坚持。


第08天学习笔记:

1、懒加载代码复习

model中封装字典转模型,加载plist文件

+ (NSArray *)messagesList

{

    //读取plist

    NSString *path = [[NSBundlemainBundle] pathForResource:@"messages"ofType:@"plist"];

    NSArray *dicArray = [NSArrayarrayWithContentsOfFile:path];

    //字典转模型

    NSMutableArray *tmpArray = [NSMutableArrayarray];

    //上一条消息

    CZMessage *preMessage;

    for (NSDictionary *dicin dicArray) {

        CZMessage *message = [CZMessagemessageWithDic:dic];

        //获取上一条消息

//        preMessage = [tmpArray lastObject];

        

        if ([message.timeisEqualToString:preMessage.time]) {

            //时间相等隐藏

            message.hiddenTime = YES;

        }        

        [tmpArray addObject:message];

        

        //获取上一条消息

        preMessage = message;

    }

    return tmpArray;

}

controller中进行懒加载:

//1 懒加载

- (NSArray *)messageFrames

{

    if (_messageFrames ==nil) {

        //1.1 加载模型数据

        NSArray *messages = [CZMessagemessagesList];

        NSMutableArray *tmpArray = [NSMutableArrayarray];

        //1.2 创建frame模型

        for (CZMessage *msgin messages) {

            CZMessageFrame *msgFrame = [[CZMessageFramealloc] 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 = [UIColorcolorWithRed:240/255.0green:240/255.0blue:240/255.0alpha: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 = [UIScreenmainScreen];

    

    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 [textboundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOriginattributes:@{NSFontAttributeName:[UIFontsystemFontOfSize:fontSize]}context:nil].size;

}


7、设置QQ聊天背景图片的代码示范:

 //设置消息的背景图片

    if (msg.type ==CZMessageTypeSelf) {

        

        

        

//        [bgImage resizableImageWithCapInsets:<#(UIEdgeInsets)#>]

//        [bgImage resizableImageWithCapInsets:<#(UIEdgeInsets)#> resizingMode:(UIImageResizingMode)]

        [self.textViewsetBackgroundImage:[UIImageresizeImage:@"chat_send_nor"]forState:UIControlStateNormal];

        [self.textViewsetBackgroundImage:[UIImageresizeImage:@"chat_send_press_pic"]forState:UIControlStateHighlighted];

    }else{

        

        [self.textViewsetBackgroundImage:[UIImageresizeImage:@"chat_recive_nor"]forState:UIControlStateNormal];

        [self.textViewsetBackgroundImage:[UIImageresizeImage:@"chat_recive_press_pic"]forState:UIControlStateHighlighted];

    }


8、图片的缩放代码示范:

//缩放图片(平铺)

- (UIImage *)resizeImage:(NSString *)imgName

{

    UIImage *bgImage =  [UIImageimageNamed:imgName];

    //缩放图片

    bgImage = [bgImage stretchableImageWithLeftCapWidth:bgImage.size.width /2 topCapHeight:bgImage.size.height /2];

    return bgImage;

}





1 0
原创粉丝点击