美文网首页
collectionview 新手引导

collectionview 新手引导

作者: aasdsjk | 来源:发表于2017-03-30 20:23 被阅读0次

Swift使用collectionview写的新手引导

直接上代码:

import UIKitlet

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(incollectionView: UICollectionView) -> Int {        return1}  

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.    }/*

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=10btn.layer.masksToBounds= true        btn.layer.borderWidth=1btn.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也可以用来做轮播图

另外推荐一个自己写的弹出自定义视图的工具,支持pod[给个Star](https://github.com/aasdsjk/JKViewAnimation)

相关文章

  • collectionview 新手引导

    Swift使用collectionview写的新手引导 直接上代码: import UIKitlet leadIm...

  • iOS新手引导--GuideImageView(二)

    iOS新手引导--GuideImageView(一)iOS新手引导--GuideImageView(二)iOS新手...

  • 联想--次留影响因素

    1、新手引导 新手引导的分节点流失统计 不同新手引导方案的次留比较 2、机型适配 次日流失用户的机型分布 3、美术...

  • 妄想之后,还需靠数据说话

    笔者近期在做一个快递单打印产品的新手引导改版,有同学提问,“整个流程那么简单有必要新手引导吗?”,“即使有新手引导...

  • 新手引导

    新手引导:https://github.com/weiming4219/ZWMGuideView https://...

  • 新手引导

  • 新手引导设计,这样改善太棒了!

    新手引导,又可称为新手帮助。对于新手引导使用最多的就是电子游戏行业,特别是国内的网络游戏行业,作用就是将规则以简单...

  • 后台新手引导

    完美的流程就是最好的新手引导。 关联操作一定要归到同一个流程,比如创建新项目后马上添加成员权限并给出参数,指引用户...

  • 新手引导系统

    新手引导是游戏中必不可少的系统。 原理:1.添加一个灰色的遮罩层2.高亮显示引导玩家的内容,比如需要点击的按钮3....

  • Android打造不一样的新手引导页面(二)

    Android打造不一样的新手引导页面(二) 本系列主要分为两篇博客 Android打造不一样的新手引导页面(一)...

网友评论

      本文标题:collectionview 新手引导

      本文链接:https://www.haomeiwen.com/subject/zmipottx.html