Creating a Vertical UIPageControl
Anyone have an idea how to create a vertical UIPageControl? I have a UIScrollView with pagination enabled and I would like to have the UIPageControl sit on the side and appear vertically instead of horizontally.
Thank you in开发者_如何转开发 advance...
You can apply a rotation transformation to the UIPageControl.
pageControl.transform = CGAffineTransformMakeRotation(M_PI_2);
Swift 3.0
let angle = CGFloat(M_PI_2)
pageControl.transform = CGAffineTransform(rotationAngle: angle)
Swift 4.0
let angle = CGFloat.pi/2
pageControl.transform = CGAffineTransform(rotationAngle: angle)
Update for Swift 3.1
pageControl.transform = pageControl.transform.rotated(by: .pi/2)
You can use UICollectionView
with paging enabled and vertical scroll. This handles the vertical pagination automatically.
page control has subviews, which must be rotated to make vertical dots
//create page control
private let pageControl: UIPageControl = {
let pageControl = UIPageControl()
pageControl.numberOfPages = 3
return pageControl
}()
//add page control as a subview to container UIView
override func viewDidLoad() {
pageViewContainer.addSubview(pageControl)
}
//rotate it vertically
override func viewWillLayoutSubviews() {
pageControl.frame = pageViewContainer.bounds
pageControl.subviews.last?.transform = CGAffineTransform(rotationAngle: CGFloat.pi/2)
pageControl.subviews.first?.transform = CGAffineTransform(rotationAngle: CGFloat.pi/2)
}
精彩评论