久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何使用 swift 創建帶有頁面控件的滾動視圖?

How to create a Scroll View with a page control using swift?(如何使用 swift 創建帶有頁面控件的滾動視圖?)
本文介紹了如何使用 swift 創建帶有頁面控件的滾動視圖?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試創建具有視圖數量的頁面視圖控制器.我想要一個使用 UIPageViewController 的簡單代碼示例.

I am trying to create a Page View controller with numbers of view. I want a simple code sample that will use UIPageViewController.

推薦答案

import UIKit

class DummyVC: UIViewController, UIScrollViewDelegate {

    let scrollView = UIScrollView(frame: CGRect(x:0, y:0, width:320,height: 300))
    var colors:[UIColor] = [UIColor.red, UIColor.blue, UIColor.green, UIColor.yellow]
    var frame: CGRect = CGRect(x:0, y:0, width:0, height:0)
    var pageControl : UIPageControl = UIPageControl(frame: CGRect(x:50,y: 300, width:200, height:50))    

    override func viewDidLoad() {
        super.viewDidLoad()

        configurePageControl()

        scrollView.delegate = self
        scrollView.isPagingEnabled = true

        self.view.addSubview(scrollView)
        for index in 0..<4 {

            frame.origin.x = self.scrollView.frame.size.width * CGFloat(index)
            frame.size = self.scrollView.frame.size

            let subView = UIView(frame: frame)
            subView.backgroundColor = colors[index]
            self.scrollView .addSubview(subView)
        }

        self.scrollView.contentSize = CGSize(width:self.scrollView.frame.size.width * 4,height: self.scrollView.frame.size.height)
        pageControl.addTarget(self, action: #selector(self.changePage(sender:)), for: UIControlEvents.valueChanged)

    }

    func configurePageControl() {
        // The total number of pages that are available is based on how many available colors we have.
        self.pageControl.numberOfPages = colors.count
        self.pageControl.currentPage = 0
        self.pageControl.tintColor = UIColor.red
        self.pageControl.pageIndicatorTintColor = UIColor.black
        self.pageControl.currentPageIndicatorTintColor = UIColor.green
        self.view.addSubview(pageControl)

    }

    // MARK : TO CHANGE WHILE CLICKING ON PAGE CONTROL
    func changePage(sender: AnyObject) -> () {
        let x = CGFloat(pageControl.currentPage) * scrollView.frame.size.width
        scrollView.setContentOffset(CGPoint(x:x, y:0), animated: true)
    }

    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {

        let pageNumber = round(scrollView.contentOffset.x / scrollView.frame.size.width)
        pageControl.currentPage = Int(pageNumber)
    }

}

這篇關于如何使用 swift 創建帶有頁面控件的滾動視圖?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to subclass UIScrollView and make the delegate property private(如何繼承 UIScrollView 并使委托屬性私有)
Swift - how to get last taken 3 photos from photo library?(Swift - 如何從照片庫中獲取最后拍攝的 3 張照片?)
Setting contentOffset programmatically triggers scrollViewDidScroll(以編程方式設置 contentOffset 觸發 scrollViewDidScroll)
Photos app-like gap between pages in UIScrollView with pagingEnabled(使用 pagingEnabled 的 UIScrollView 中頁面之間的照片應用程序式間隙)
why UIScrollView is leaving space from top in ios 6 and ios 7(為什么 UIScrollView 在 ios 6 和 ios 7 中從頂部留下空間)
UIScrollView pauses NSTimer while scrolling(UIScrollView 在滾動時暫停 NSTimer)
主站蜘蛛池模板: 久久久高清 | 中国一级特黄真人毛片免费观看 | 国产女人与拘做受视频 | 国产1区2区在线观看 | 激情五月婷婷丁香 | 久久大 | 欧美中文在线 | 亚洲精品中文字幕在线 | 亚洲欧美中文日韩在线v日本 | 国产三区在线观看视频 | 91精品国产欧美一区二区 | 日韩精品一区二区三区在线观看 | 国产91观看 | 日韩欧美在线观看 | 午夜影院在线观看 | 国产丝袜一区二区三区免费视频 | 久在线 | 国产高清视频 | 国内精品久久久久久久影视简单 | 免费视频久久 | 国产欧美日韩综合精品一区二区 | 九九热精| 亚洲国产一区二区三区在线观看 | 久久亚洲国产精品日日av夜夜 | 久久久一| 欧美成人a∨高清免费观看 色999日韩 | 中文字幕在线播放第一页 | 亚洲免费人成在线视频观看 | 在线色 | 亚洲国产一区二区视频 | 久久久免费在线观看 | 国产婷婷综合 | 中文字幕免费在线观看 | 91精品国产综合久久小仙女图片 | 成人国产在线观看 | 操一草| 亚洲欧美中文日韩在线v日本 | 99热精品在线 | 久久久91 | 99久久99久久精品国产片果冰 | 久久久久久综合 |