日常阅读

Swift-消息滚动、轮播图、选择相片库、富文本修改颜色添加可点

2023-06-28  本文已影响0人  chushen61

Swift一个项目告一段落总结下项目中使用的六个组件,选择相片库、富文本修改颜色添加可点击事件、消息滚动、轮播图、日历组件、Json动画

1.选择相片库分为两种,一种修改头像选择一张照片,采用系统方法提供的UIImagePickerController方法,第二种选择多张图 #图片选择 

pod 'CLImagePickerTool', :git => 'https://github.com/Darren-chenchen/CLImagePickerTool.git'

pod 'YBImageBrowser'  #图片浏览框架

pod 'YBImageBrowser/Video'

多种选择无法对图片进行展示、删除、放大的效果,需自定义CollectionView,和自定义放大的效果图

2.富文本修改颜色添加点击事件,实现思路,采用UITextView的attributedText 先修改部分字体颜色,根据修改的字体颜色,执行UITextViewDelegate的代理包含URL这截的字,执行点击跳转事件,执行代码仅供参考:

                let attributedText = ruleString.setHtmlAttributedString(font:UIFont.systemFont(ofSize: 13),colorSelect: UIColor.TB_hexColor("#999999"),lineSpacing: 5,paragraphSpacing: 12)

                guardletrange = attributedText.string.range(of:"新手挑战活动")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

执行代理方法:

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查询很多相关组件 calendarKit

6.Json动画  json动画对比GIF动画差异,详细可看上一遍文章

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

        }

上一篇 下一篇

猜你喜欢

热点阅读