swift的轮播

private lazy var scrollView:UIScrollView = {
let scrollView = UIScrollView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 200))
scrollView.contentSize = CGSize(width: 3*(UIScreen.main.bounds.width), height: 200)
scrollView.bounces = false
scrollView.isPagingEnabled = true
scrollView.showsVerticalScrollIndicator = false
scrollView.showsHorizontalScrollIndicator = false
scrollView.backgroundColor = UIColor.red
//scrollView.delegate = self
let imgArr = ["“,"",""] //放轮播的图片
for i in 0..<imgArr.count {
let imgView = UIImageView(frame: CGRect(x: i*Int(UIScreen.main.bounds.width), y: 0, width: Int(UIScreen.main.bounds.width), height: 200))
scrollView.addSubview(imgView)
imgView.image = UIImage(named: imgArr[i])
}
return scrollView
}()
private lazy var pageNum:UIPageControl = {
let pageNum = UIPageControl(frame: CGRect(x: (UIScreen.main.bounds.width-100)/2, y: 170, width: 100, height: 10))
pageNum.currentPage = 0
pageNum.numberOfPages = 3
pageNum.currentPageIndicatorTintColor = UIColor.red
pageNum.pageIndicatorTintColor = UIColor.blue
return pageNum
}()
viewDidLoad()里的
self.view.backgroundColor = UIColor.white
self.view.addSubview(scrollView)
self.view.addSubview(pageNum)


