Tomi_iOS開發(fā)周報(第一期)

標(biāo)簽(空格分隔): ios 開發(fā)中的那些坑


[TOC]

一、UITableview 使用技巧分享

分享人:@錢萌丹 @官洋 @老戴

tableViewCell 選中后背景View更換

// 使用selectedBackgroundView 可設(shè)置tableViewCell選中背景
// 注意使用該屬性的前提是,UITableViewCell的選中狀態(tài)類型不能設(shè)置為UITableViewCellSelectionStyleNone
tableViewCell.selectedBackgroundView 

cell下方分割線如何縮進(jìn)

#pragma mark 設(shè)置tableview分割線到頂端
-(void)viewDidLayoutSubviews{
    
    NSLog(@"%s",__FUNCTION__);
    if ([self.mainTableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.mainTableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
    }
    
    if ([self.mainTableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.mainTableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
    }
}

#pragma mark delegate
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 解決separator 線的縮進(jìn)
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
   // 解決tableViewCell 8像素縮進(jìn) 
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

二、UIScrollView 使用技巧分享

分享人 : @李銳

如果想設(shè)置UIScrollView的偏移量?

scrollView.contentInset = UIEdgeMake(64, 0, 0, 0);

三、UIImage 使用技巧分享

分享人: @王孜

UIImage 之前加載使用的file刪除,再次存儲UIImage到文件失敗

  • BUG出現(xiàn)描述
    <Error>: ImageIO: CGImageReadCreateDataWithMappedFile 'open' failed '路徑'
    error = 2 (No such file or directory)

  • BUG出現(xiàn)操作還原

  1. 從本地沙盒讀取圖片,加載到UIimageViews上。

  2. 刪除沙盒里的圖片。

  3. 將UIImageView里的圖片保存到本地沙盒時,BUG出現(xiàn)。

  • BUG出現(xiàn)原因解析與解決方法
    原因:保存時,圖片已經(jīng)不存在了,所以保存失敗。
    解決方案:從路徑讀取圖片后,先轉(zhuǎn)換成NSData,再生成一張新的image,之后保存就OK。

// 正確做法
   UIImage *tempImage = [[UIImage alloc] initWithContentsOfFile:filePath];
   NSData *tempData = UIImagePNGRepresentation(tempImage);
   UIImage *newImage = [UIImage imageWithData:tempData];
// 錯誤做法
    UIImage *newImage = [[UIImage alloc] initWithContentsOfFile:filePath];
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容