实习笔记:uiscrollview与pagecontrol的综合应用
2017-09-05 22:09
459 查看
实习开发iOS地图租车界面时用到的界面UI元素。
趁有空在这里记录一下。
这是引入项目之前拿来做小测试的小小demo。
import UIKit
class ViewController: UIViewController,UIScrollViewDelegate {
}
趁有空在这里记录一下。
这是引入项目之前拿来做小测试的小小demo。
import UIKit
class ViewController: UIViewController,UIScrollViewDelegate {
@IBOutlet weak var myScrollView: UIScrollView! var codePageControl: UIPageControl! func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { let currentPageNumber = Int(round(myScrollView.contentOffset.x / scrollView.frame.size.width)) codePageControl.currentPage = currentPageNumber } func codePageControlAction(sender: UIPageControl) { let currentPageNumber = sender.currentPage let width = myScrollView.frame.size.width let offset = CGPoint(x: width * CGFloat(currentPageNumber), y: 0) myScrollView.setContentOffset(offset, animated: true) } override func viewDidLayoutSubviews() { myScrollView.contentSize.width = myScrollView.frame.width * 3 let viewColors = [UIColor.red,UIColor.green,UIColor.blue] for i in 0..<3{ let oneView = UIView( frame: CGRect( x: CGFloat(i) * myScrollView.frame.size.width, y: 0, width: myScrollView.frame.size.width, height: myScrollView.frame.size.height)) oneView.backgroundColor = viewColors[i] myScrollView.addSubview(oneView) } myScrollView.isPagingEnabled = true myScrollView.bounces = false //建立PageControl codePageControl = UIPageControl(frame: CGRect(x: view.frame.size.width/2 - 30, y: view.frame.size.height - 50, width: 60, height: 37)) codePageControl.pageIndicatorTintColor = UIColor.black codePageControl.currentPageIndicatorTintColor = UIColor.lightGray codePageControl.numberOfPages = 3 codePageControl.currentPage = 0 codePageControl.addTarget(self, action: #selector(ViewController.codePageControlAction(sender:)), for: .valueChanged) view.addSubview(codePageControl) }
}
相关文章推荐
- iPhone相册,(UIScrollView,UIPageControl的综合应用)捏合放大缩小, 左右滑动切换图片
- 顶部可滚动小广告位 的封装 (UIScrollView+PageControl)
- ios例子12 pageControl和UIScrollView
- 第二十三篇:UITableView,UIScrollView,NSTimer,UIButton综合应用代码---团购
- (九)UIScrollView和PageControl的分页
- iOS-UIScrollView和UIPageControl的综合实力,滚动图,轮播图
- (九)UIScrollView和PageControl的分页
- 图片轮播器(UIScrollView-UIPageControl)
- 笔记8-27(自定义UIScrollView,添加手势识别,UIPageControl使用)
- IOS_UI_UIScrollview UIPageControl结合 应用
- UIScrollView+PageControl 翻页提示
- UIScrollView--UIPageControl
- iOS学习之TableView和UIScrollView的综合小应用
- [IOS UIScrollView+PageControl]信息展示横幅
- iOS中UIScrollView和UIPageControl以及NSTimer的综合使用
- UIScrollView结合UIPageControl+NSTimer使用简介
- 学习IOS开发UI篇--UIScrollView/delegate/pagecontrol/UITimer
- UIScrollView和自定义PageControl的结合使用
- UI一揽子计划 7 ( UIScrollView、 UIPageControl、综合所学简单相册)
- 【iOS系列】-UIScrollView的介绍及结合UIPageControl实现图片播放的实例