UI學習第08天

jason_ze發表於2016-03-09

  最近一段時間自己的學習狀態真的很差,甚至到了一度想要放棄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;

}





相關文章