码迷,mamicode.com
首页 > 编程语言 > 详细

Swift小练习-引导页

时间:2016-12-31 07:20:03      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:enumerate   ima   nal   cond   sub   review   idt   size   tintcolor   

任何一门语言,只要长期不用就会忘掉,得时不时的敲敲小项目,练练手;

    let scrollViewBG = UIScrollView.init(frame: SLScreenRect)

    let images = ["first","second","third"]

    let pageControl = UIPageControl.init(frame: CGRect.init(x: 0, y: SLScreenHeight - 30, width: SLScreenWidth, height: 20))

    var currentPage = 0

    

    override var prefersStatusBarHidden: Bool {

        return true

    }

 

    override func viewDidLoad() {

        super.viewDidLoad()

        // Do any additional setup after loading the view, typically from a nib.

        

        configureView()

        

    }

  func configureView() {

        // 遍历数组,同时获得index

        for (index, value) in images.enumerated() {

            let imageView = UIImageView.init(frame: CGRect.init(x: CGFloat(index)*SLScreenWidth, y: 0, width: SLScreenWidth, height: SLScreenHeight))

            imageView.image = UIImage.init(named: value)

            // 限制边界

            imageView.clipsToBounds = true

            imageView.contentMode = .scaleAspectFill

            scrollViewBG .addSubview(imageView)

            

        }

        

       // 协议

        scrollViewBG.delegate = self

        scrollViewBG.isPagingEnabled = true

        scrollViewBG.showsHorizontalScrollIndicator = false

        scrollViewBG.contentSize = CGSize.init(width: SLScreenWidth*CGFloat(images.count), height: SLScreenHeight)

        // pagecontol

        pageControl.numberOfPages = images.count

        pageControl.currentPageIndicatorTintColor = .white

        pageControl.pageIndicatorTintColor = .lightGray

        pageControl.currentPage = currentPage

        pageControl.isEnabled = false

        

        

        view.addSubview(scrollViewBG)

        view.addSubview(pageControl)

        

    }

 

  //MARK: - 协议方法

    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {

        currentPage = Int(scrollView.contentOffset.x/SLScreenWidth)

        pageControl.currentPage = currentPage

    }

 技术分享

 

Swift小练习-引导页

标签:enumerate   ima   nal   cond   sub   review   idt   size   tintcolor   

原文地址:http://www.cnblogs.com/liuzicheng/p/6238600.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!