collectionview写的新手引导
2016-12-20 14:13
405 查看
swift 使用collectionview写的新手引导
直接上代码:
轮播图也可以使用collectionview写的。。
权当自己做个笔记了。。
swift 版本 没有什么动画,这个collectionview也可以用来做轮播图
直接上代码:
import UIKit let leadImageNameArr = ["start1","start2","start3","start4"] class TTLeadNewUserViewController: UIViewController,UICollectionViewDelegate,UICollectionViewDataSource { var collectionView : UICollectionView! override func viewDidLoad() { super.viewDidLoad() setUpCollectionView() } fileprivate func setUpCollectionView() { let layout = UICollectionViewFlowLayout() layout.itemSize = CGSize.init(width: MainWide, height: MainHeight) layout.minimumLineSpacing = 0 layout.minimumInteritemSpacing = 0 layout.scrollDirection = .horizontal collectionView = UICollectionView.init(frame: self.view.bounds, collectionViewLayout: layout) collectionView.isPagingEnabled = true collectionView.register(LeadImageCollectionCell.self, forCellWithReuseIdentifier: "LeadImageCollectionCell") collectionView.dataSource = self collectionView.delegate = self collectionView.showsHorizontalScrollIndicator = false self.view.addSubview(collectionView) } func numberOfSections(in collectionView: UICollectionView) -> Int { return 1 } func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return leadImageNameArr.count } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "LeadImageCollectionCell", for: indexPath) as! LeadImageCollectionCell cell.setImage(leadImageNameArr[indexPath.row]) if indexPath.row == leadImageNameArr.count - 1 { cell.setButtonOnImage() } return cell } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // Get the new view controller using segue.destinationViewController. // Pass the selected object to the new view controller. } */ } class LeadImageCollectionCell: UICollectionViewCell { fileprivate var imageView : UIImageView! fileprivate var button : UIButton? override init(frame: CGRect) { super.init(frame: frame) setUpImage(frame) } fileprivate func setUpImage(_ frame:CGRect) { imageView = UIImageView() self.contentView.addSubview(imageView) } override func layoutSubviews() { imageView.frame = CGRect.init(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height) } open func setImage(_ imageName : String){ removeButton() imageView.image = UIImage.init(named: imageName) } func removeButton() { if button != nil { button?.removeFromSuperview() } } func setButtonOnImage() { let btn = UIButton.init(type: .custom) btn.frame = CGRect.init(x: MainWide*0.25, y: MainHeight*0.8, width: MainWide*0.5, height: MainHeight*0.05) btn.setTitleColor(UIColor.collorWirhRGB(r: 227, g: 62, b: 42), for: .normal) btn.setTitle("立即体验", for: .normal) btn.layer.cornerRadius = 10 btn.layer.masksToBounds = true btn.layer.borderWidth = 1 btn.layer.borderColor = UIColor.orange.cgColor btn.addTarget(self, action: #selector(goHomeVc), for: UIControlEvents.touchUpInside) button = btn self.contentView.addSubview(btn) } @objc func goHomeVc(){ //跳转到homeVc //TTPopTool.gohomeVc() } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } }
轮播图也可以使用collectionview写的。。
权当自己做个笔记了。。
swift 版本 没有什么动画,这个collectionview也可以用来做轮播图
相关文章推荐
- coco2d-x CCScrollView实现关卡选择 新手引导 帮助界面
- Android学习——自定义View实现蒙版新手引导(二)
- Android学习——自定义View实现蒙版新手引导
- android应用新手引导切换界面-ViewPager与PagerAdapter
- coco2d-x CCScrollView实现关卡选择 新手引导 帮助界面
- 新手CrossApp 之CollectionView小结
- collectionView代理事件 相关处理 iOS 新手笔记
- ViewPager 实现引导页
- UICollectionViewController与引导页
- 可移动的CollectionViewCell
- egret 适配问题 优化问题 新手引导
- IOS CollectionView 拖拽移动
- 谈谈游戏中新手引导是如何制作的
- 给ViewPager添加引导点
- 新手看招 Linux操作系统的几种引导方法
- iOS collectionView返回顶部
- 【转】Android开发必知--WebView加载html5实现炫酷引导页面
- 使用ViewPager动画来做出不一样的引导页
- 使用CSStickyHeaderFlowLayout实现头部固定的CollectionView
- Android通过ViewPager实现引导界面(一)