今天根据网路上的资料,试做了一个日历跟使用Lottie套件,未来要作为使用
介绍一下Lottie套件:
是一个第三方套件,一般在ios程序中,如果要有动画看起来比较美观,但又不想花时间画动画,可以使用Lottie套件,网路上都有现成的动画,可以使用,使用方式也非常简单。
新增(Podfile内)
pod 'lottie-ios'
安装(在Terminal上)
pod install
新增一个UIView
在这个UIView的 Custom class(右侧的Identity面板中)
设定class 为 AnimationView
设定Module 为 Lottie
设定Animation Name (Attribute面板)
新增一个ViewController
// 新增一个IBOutlet
@IBOulet weak var Loading: AnimationView!
override func viewDidLoad(){
super.viewDidLoad()
// 设定动画循环播放
Loading.loopMode = .loop
// 新增到view的SubView
self.view.addSubview(Loading)
// 开始播放
Loading.play()
}
成果展示:
教程网址:
抓了几个重点流程
//计算这个月有几天
var numberofDay:Int{
let datecomponents = DateComponents(year:CurrentYear, month:CurrentMonth)
let date = Calender.current.date(from: datecomponents)!
let range = Calender.current.ranger(of: .day, in: .month, for: date)
return range.count ?? ""
}
//计算这周第一天是哪天
var firstDayofMonth:Int{
let datecomponents = DateComponents(year:CurrentYear, month:CurrentMonth)
let date = Calender.current.date(from: datecomponents)!
return Calender.current.component(.weekday, from:date)
}
// 多少个Section
func numberOfSections(in collectionView: UICollectionView) -> Int {
// 多少个日子
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// 计算有几天+跟有几天格子内没有字
return numberofDay + (firstDayofMonth-1)
// CollectionViewCell内该长什麽样子
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
// 使用DequeueReusableCell
let ReuseCell = collectionView.dequeueReusableCell(withReuseIdentifier:"Reusecell", for: indexPath)
// 转型成UILabel
if let textfield = Reusecell.contentView.subView[0] as? UILabel{
// 如果这个月第一天是礼拜五,那麽前五个格子都要空着
if indexPath.row < (firstDayofMonth-1){
textfield.text = ""
}else{
// 剪去掉刚刚算去前面五个空的格子
textfield.text = "\(indexPath.row + 1 - (firstDayofMonth-1))
}
// Cell之间的水平距离
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
// Cell之间的垂直距离
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
// Cell的宽度
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
// 让宽度成为一周七天
let width = collectionView.frame.width / 7
// 设定完要去CollectionView的size Inspector(右侧的面板)内设定Estimate size设定为None,否则是不会改变
// 设置好 CollectionView重新reload跟月份的更新
func setup(){
大家好,我是西瓜,你现在看到的是 2021 iThome 铁人赛『如何在网页中绘制 3D 场景?从 ...
& 常见使用&的状况如下 :007 > [1, 2, 3].map(&...
最近在准备转行学python,此前学过一段时间JAVA,想来问问大神们有什么好的资料分享吗?之前在其...
今天看 Immutability(不可变),作者提供适用於不同情境的四种方法,将物件设定为不可更变的...
不罗嗦! 直接上图 基本上要先在odoo原生的Xml找到你要放置新栏位的位置, 然後使用xpath语...