SkeletonView一种优雅的方式,向用户显示正在发生的事情,并为他们正在等待的内容做好准备
1.安装
pod "SkeletonView"
2.如何使用
2.1在适当的位置导入SkeletonView
import SkeletonView
2.2设置视图skeletonables
avatarImageView.isSkeletonable = true
2.3显示骨架
1 | view.showSkeleton() // Solid |
2.4更新骨架(如颜色,动画等)
1 | view.updateSkeleton() // Solid |
2.5隐藏骨架
1 | view.hideSkeleton() |
3.UITableView
3.1遵守SkeletonTableViewDataSource
协议,并实现协议方法
1 | extension SearchMovieViewController: SkeletonTableViewDataSource { |
3.2 设置视图skeletonables
1 | class SearchMovieCell: DiaryBaseTableViewCell { |
3.3 显示骨架
1 | self.searchMovieView.tableView.visibleCells.forEach { $0.showAnimatedGradientSkeleton(usingGradient: SkeletonGradient(baseColor: UIColor.clouds),animation: GradientDirection.topLeftBottomRight.slidingAnimation()) } |
4.UICollectionView
4.1 遵守SkeletonCollectionViewDataSource
协议,并实现协议方法
1 | func collectionSkeletonView(_ skeletonView: UICollectionView, cellIdentifierForItemAt indexPath: IndexPath) -> ReusableCellIdentifier { |
4.2 设置视图skeletonables
1 | class MovieHomeCell: DiaryBaseCollectionViewCell { |
3.3 显示骨架
1 | view.isSkeletonable = true |