Swift一個項目告一段落總結(jié)下項目中使用的六個組件凛虽,選擇相片庫、富文本修改顏色添加可點擊事件广恢、消息滾動凯旋、輪播圖、日歷組件钉迷、Json動畫
1.選擇相片庫分為兩種至非,一種修改頭像選擇一張照片,采用系統(tǒng)方法提供的UIImagePickerController方法糠聪,第二種選擇多張圖 #圖片選擇?
pod 'CLImagePickerTool', :git => 'https://github.com/Darren-chenchen/CLImagePickerTool.git'
pod 'YBImageBrowser'? #圖片瀏覽框架
pod 'YBImageBrowser/Video'
多種選擇無法對圖片進(jìn)行展示荒椭、刪除、放大的效果舰蟆,需自定義CollectionView趣惠,和自定義放大的效果圖
2.富文本修改顏色添加點擊事件,實現(xiàn)思路身害,采用UITextView的attributedText 先修改部分字體顏色味悄,根據(jù)修改的字體顏色,執(zhí)行UITextViewDelegate的代理包含URL這截的字塌鸯,執(zhí)行點擊跳轉(zhuǎn)事件侍瑟,執(zhí)行代碼僅供參考:
? ? ? ? ? ? ? ? let attributedText = ruleString.setHtmlAttributedString(font:UIFont.systemFont(ofSize: 13),colorSelect: UIColor.TB_hexColor("#999999"),lineSpacing: 5,paragraphSpacing: 12)
? ? ? ? ? ? ? ? guardletrange = attributedText.string.range(of:"新手挑戰(zhàn)活動")else{// Range<String.Index>?
? ? ? ? ? ? ? ??return
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? letconvertedRange =NSRange(range,in: attributedText.string)// NSRange?
? ? ? ? ? ? ? ? attributedText.addAttribute(.link,value:"more://",range: convertedRange)// NSRange? ? ? ? ? ? ? ? ? attributedText.addAttributes([NSAttributedString.Key.foregroundColor:UIColor.TB_hexColor("#FF7650")],range: convertedRange)
? ? ? ? ? ? ? ? letparaph =NSMutableParagraphStyle()
?? ? ? ? ? ? ? ?paraph.lineSpacing=2
?? ? ? ? ? ? ? ?paraph.paragraphSpacing=0
? ? ? ? ? ? ? ? attributedText.addAttributes([NSAttributedString.Key.paragraphStyle: paraph],range:NSMakeRange(0, attributedText.length))
? ? ? ? ? ? ? ??self.inviteTextView.isEditable=false
? ? ? ? ? ? ? ? self.inviteTextView.isScrollEnabled=false
? ? ? ? ? ? ? ? self.inviteTextView.delegate=self// 指定代理處理點擊方法
? ? ? ? ? ? ? ? self.inviteTextView.attributedText= attributedText
? ? ? ? ? ? ? ? self.inviteTextView.textColor=UIColor.TB_hexColorA("#646464",0.8)
? ? ? ? ? ? ? ? lettextSize = attributedText.boundingRect(with:CGSize(width:kScreenWidth-44,height:CGFloat.greatestFiniteMagnitude),options: [.usesLineFragmentOrigin, .usesFontLeading],context:nil).size.height
執(zhí)行代理方法:
extension LTInviteRedController : UITextViewDelegate {
? ? functextView(_textView:UITextView,shouldInteractWithURL: URL,incharacterRange:NSRange,interaction:UITextItemInteraction) ->Bool{
? ? ? ? ifURL.absoluteString=="more://"{
? ? ? ? ? print("click more")
? ? ? ? ? ??letchallenge =LTChallengeDetailsController.init()
? ? ? ? ? ? challenge.challengeGuid=challengGuid
? ? ? ? ? ? self.navigationController?.pushViewController(challenge,animated:true)
? ? ? ? ? returnfalse
? ? ? ? }
? ? ? ? return true
? ? ? }
}
3.消息滾動采用 JJMarqueeView ?
4.輪播圖采用
FSPagerView
僅供參考:https://blog.csdn.net/chenyong05314/article/details/105639112
5.日歷組件,時間允許的情況可自定義也可github查詢很多相關(guān)組件 calendarKit
6.Json動畫 ?json動畫對比GIF動畫差異,詳細(xì)可看上一遍文章
pod 'lottie-ios'
letanimationView =AnimationView(name:"inviteData")
? ? ? ? animationView.frame=CGRect(x:0,y:0,width:kScreenWidth,height:kScreenWidth*410/375)
? ? ? ? self.FirstBackView.addSubview(animationView)
? ? ? ? animationView.contentMode= .scaleToFill
? ? ? ? animationView.loopMode= .loop
? ? ? ? animationView.play()
? ? ? ? animationView.play{ (isFinished)in
? ? ? ? }