久久久久久久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)
主站蜘蛛池模板: 精品视频在线免费观看 | 男女羞羞视频在线看 | 日韩三级| 成人一区av偷拍 | 操操日 | 草草视频在线观看 | 午夜久久久 | 国产精品一区二区三级 | 免费一区 | 久久久久国产一区二区三区 | 亚洲欧美日韩久久 | 九九亚洲 | 天堂一区二区三区 | 99re在线视频观看 | 青青草视频网站 | 欧美精品一区在线 | 日韩欧美网 | 亚洲区视频 | 久久中文一区二区 | 欧美亚洲另类丝袜综合网动图 | 97福利在线 | 精品久久久久久久久久久久久久 | 欧美日韩高清在线观看 | 精品国产一区久久 | 做a网站| 亚洲欧美日韩一区 | 欧美一级精品片在线看 | 亚洲区一区二 | 免费在线观看h片 | 91精品国产91久久综合桃花 | 黄色在线免费网站 | 岛国二区 | 成人性生交大免费 | 99久久99| a在线v| 亚洲高清网 | 日韩免费一二三区 | 九九久久精品 | 日韩免费一区 | 中文字字幕在线中文乱码范文 | 国产在线精品一区二区三区 |