滚动视图(UIScrollView)
滚动视图的创建
let scr = UIScrollView(frame:CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height))
设置内容的区域的大小(滑动的区域)
scr.contentSize = CGSize(width: self.view.frame.size.width * 4, height: self.view.frame.size.height)
把滚动视图添加到view
self.view.addSubview(scr)
滚动视图的设置偏移量
scr.contentOffset = CGPoint(x: self.view.frame.size.width, y: 0)
滚动视图是否整页翻动,默认是不翻动
cr.isPagingEnabled = true
滚动视图触壁反弹(在UIScrollView的边界时在再拉拉不动了)
scr.bounces = false
滚动视图展示滑动条(true:显示滑动条 false:关闭滑动条)
scr.showsHorizontalScrollIndicator = true
滚动视图设置滑动条的颜色
scr.indicatorStyle = .black
滚动视图是否关闭拖拽
scr.isScrollEnabled = false
网友评论