Skip to content

Instantly share code, notes, and snippets.

Created April 16, 2015 01:27
Show Gist options
  • Save SixArm/9b5641accf56ff936e65 to your computer and use it in GitHub Desktop.
Save SixArm/9b5641accf56ff936e65 to your computer and use it in GitHub Desktop.
Xcode Swift Home PageControl
import UIKit
class HomeViewController: UIViewController {
@IBOutlet weak var pageControl: UIPageControl!
@IBOutlet weak var pageImageView: UIImageView!
@IBOutlet weak var pageCaptionLabel: UILabel!
var pageIndex = 0
let pageIndexMin = 0
let pageIndexMax = 2
let pages: [Page] = [
Page(imageName: "welcome.png", caption: "Welcome", ),
Page(imageName: "about.png", caption: "About"),
Page(imageName: "contact.png", caption: "Contact"),
class Page {
var index: Int!
var image: UIImage!
var caption: String!
internal init(imageName: String, caption: String) {
self.image = UIImage(named: imageName)
self.caption = caption
// MARK: - Call these methods to change which page the user sees
func pagePrev() {
if (pageIndex > pageIndexMin) {
func pageNext() {
if (pageIndex < pageIndexMax) {
func pageUpdate(index: Int) {
let page: IntroPage = pages[index]
pageControl.currentPage = index
pageImageView.image = page.image
pageCaptionLabel.text = page.caption
// MARK: - Call these methods when the user gestures on the XIB UIImageView object.
@IBAction func handleTap(sender: UITapGestureRecognizer) {
@IBAction func handleSwipeLeft(sender: UISwipeGestureRecognizer) {
@IBAction func handleSwipeRight(sender: UISwipeGestureRecognizer) {
// MARK: - Call this method when the user swipes the XIB page control object.
@IBAction func pageChange(sender: UIPageControl) {
Copy link

can u give introPage file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment