iOS多張圖片選取器

好久沒有更新簡書了,現(xiàn)在沒有那么忙了,更新一個(gè)簡書吧~

之前項(xiàng)目催的比較緊急(其實(shí)也就那么一回事),好多功能就以最低標(biāo)準(zhǔn)完成。現(xiàn)在項(xiàng)目開發(fā)告一段落,有個(gè)功能測(cè)試和產(chǎn)品幾次強(qiáng)烈建議+特別強(qiáng)調(diào)要改善改進(jìn)——“圖片選取”功能!

開始做的功能只能一張一張的選取 ,甚至還帶了裁剪功能,無法選擇長圖等,整個(gè)操作體驗(yàn)非常不友好。琢磨著要怎么實(shí)現(xiàn)?尋思結(jié)論:自己寫的話耗時(shí)不說,功能還菜的一匹!??!于是乎瞄準(zhǔn)第三方庫(git、code4App等),剛開始挑選各種神器,拿下來后先體驗(yàn)一番(時(shí)間超過1年未更新的直接忽略),最后定了“TZImagePickerController”,這尼瑪尼才是完美人生啊,功能強(qiáng)大的直接上天并開炸云彩!??!在此感謝作者為廣大開發(fā)謀幸福,git源碼地址->請(qǐng)點(diǎn)擊這里。這完全可以隨心所欲地自定義成心中的完美女神,蒼天啊,大地啊~~話不再多說,先看看我家女神的代碼(swift):

func typeImageSource(with delegate: Any, maxCount: Int, assets: Array<Any>) -> Void {

    //圖片選取

    guard let naviController = TZImagePickerController(maxImagesCount: maxCount, columnNumber: 4,

                                                      delegate: delegate as? TZImagePickerControllerDelegate,

                                                      pushPhotoPickerVc: true) else {

        return

    }

    //naviBar樣式

    naviController.navigationBar.setBackgroundImage(UIImage.fromColor(NSFLVar.sysColor), for: .default)

    naviController.naviTitleFont = UIFont.systemFont(ofSize: 17.0)

    naviController.barItemTextFont = UIFont.systemFont(ofSize: 16.0)

    naviController.modalPresentationStyle = .fullScreen

    //在內(nèi)部顯示拍照按鈕、在內(nèi)部顯示拍視頻按

    naviController.allowTakePicture = true

    naviController.allowTakeVideo = false

    naviController.showPhotoCannotSelectLayer = true

    naviController.cannotSelectLayerColor = UIColor.white.withAlphaComponent(0.7)

    //只選擇圖片

    naviController.allowPickingGif = false

    naviController.allowPickingImage = true

    naviController.allowPickingVideo = false

    naviController.allowPickingOriginalPhoto = false

    naviController.allowPreview = true

    //設(shè)置是否顯示圖片序號(hào)

    naviController.showSelectedIndex = false

    //自定義“返回”

    naviController.navLeftBarButtonSettingBlock = { (leftButton) -> Void in

        leftButton?.setImage(UIImage(named: "navi_bar_back_white"), for: .normal)

        leftButton?.imageEdgeInsets = UIEdgeInsets(top: 0.0, left: -30.0, bottom: 0.0, right: 0.0)

    }

    //完成樣式

    naviController.oKButtonTitleColorDisabled = NSFLVar.sysColor.withAlphaComponent(0.7)

    naviController.oKButtonTitleColorNormal = NSFLVar.sysColor

    //圖片列表是否大于0?

    if assets.count > 0 {

        naviController.selectedAssets = NSMutableArray(array: assets)

    }

    //顯示

    self.present(naviController, animated: true, completion: { () -> Void in



    })

}

以上就是核心代碼,希望對(duì)大家有個(gè)參考!

另外,在這里有點(diǎn)需要注意的,iOS12和iOS13在自定義tabBar的時(shí)候會(huì)有所不同,甚至無效(可能處理姿勢(shì)不對(duì)),我想定義成白底黑字的,但無法出效果!最后處理成非白底白字的樣式,這樣就perfect啦~

附:上面代碼直接復(fù)制后報(bào)錯(cuò),因?yàn)橛行┓椒ㄊ俏疫@邊用擴(kuò)展寫的,包括有些變量等,需自行修改!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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