Lottie套件使用 及日历制作 Day27

今天根据网路上的资料,试做了一个日历跟使用Lottie套件,未来要作为使用

介绍一下Lottie套件:

是一个第三方套件,一般在ios程序中,如果要有动画看起来比较美观,但又不想花时间画动画,可以使用Lottie套件,网路上都有现成的动画,可以使用,使用方式也非常简单。

安装

新增(Podfile内)
pod 'lottie-ios'

安装(在Terminal上)
pod install

使用

新增一个UIView

在这个UIView的 Custom class(右侧的Identity面板中)

设定class 为 AnimationView

设定Module 为 Lottie

https://i.imgur.com/nqVCfh5.png

设定Animation Name (Attribute面板)

https://i.imgur.com/xv4jov3.png

新增一个ViewController

// 新增一个IBOutlet
@IBOulet weak var Loading: AnimationView!

override func viewDidLoad(){
	super.viewDidLoad()
	// 设定动画循环播放
	Loading.loopMode = .loop
	// 新增到view的SubView
	self.view.addSubview(Loading)
	// 开始播放
	Loading.play()
}

成果展示:

https://i.imgur.com/DVOgcbk.gif

实作一个日历:

教程网址:

简单日历 (使用 Swift 4)

抓了几个重点流程

  • 两个变数:
    • 这个月有几天、这周第一天是哪天
  • 七个function
    • DataSource: 2个
    • Delegate: 4个
    • 自订: 1个

var

//计算这个月有几天
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)
}

function

// 多少个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(){
		

<<:  [day16]Vue实作-建立首页

>>:  [寿星优惠-1] 飨厚牛排 #当月寿星6折

点光源与自发光

大家好,我是西瓜,你现在看到的是 2021 iThome 铁人赛『如何在网页中绘制 3D 场景?从 ...

D-21. & 、meta programming & Monkey patch

& 常见使用&的状况如下 :007 > [1, 2, 3].map(&...

转行如何学Python ?

最近在准备转行学python,此前学过一段时间JAVA,想来问问大神们有什么好的资料分享吗?之前在其...

Day07 - this&Object Prototypes Ch3 Objects - Contents - Immutability

今天看 Immutability(不可变),作者提供适用於不同情境的四种方法,将物件设定为不可更变的...

Day 18 Odoo画面新增栏位显示

不罗嗦! 直接上图 基本上要先在odoo原生的Xml找到你要放置新栏位的位置, 然後使用xpath语...