Swift小練習-引導頁

來源:互聯網
上載者:User

標籤: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小練習-引導頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.