久久久久久久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)
主站蜘蛛池模板: 成人免费在线观看 | 激情毛片 | 噜噜噜色网 | 一区二区三区韩国 | 国产精品毛片一区二区三区 | 国产免费一区二区三区免费视频 | 亚洲成人免费 | 北条麻妃一区二区三区在线视频 | 成人毛片视频免费 | 国产成人综合一区二区三区 | 黄色欧美| 黄色一级免费 | www久久av| 一区二区三区不卡视频 | 国产91丝袜在线播放 | 亚洲国产精品成人综合久久久 | 成人精品在线观看 | 九九久久久 | 国产精品一区二区三级 | 999www视频免费观看 | 涩涩视频网 | 在线视频国产一区 | 国产精品久久网 | 蜜臀久久99精品久久久久久宅男 | 国产1区2区3区 | 91精品国产一区二区三区 | 久久99精品视频 | 99久久精品免费看国产四区 | 人人艹人人 | 国产在线视频三区 | 97国产精品视频人人做人人爱 | 97免费在线观看视频 | 日韩欧美一区二区三区在线播放 | 欧美日韩精品一区二区三区四区 | 亚洲狠狠爱 | 一级在线 | 成人免费小视频 | 美女三区| 人人九九 | av香港经典三级级 在线 | 毛片一区 |