我正在向UIPageViewController添加UIPageControle视图。我想以编程方式增加UIPageControler的高度。这是我的代码
//PageViewController
pageViewController.view.frame = bounds
// pageControl
self.pageControl.frame = CGRect(x: 0, y: 0, width: pageViewController.view.frame.width / 2, height: pageViewController.view.frame.height - 200)
self.pageControl.currentPageIndicatorTintColor = UIColor.orange
self.pageControl.pageIndicatorTintColor = UIColor.white
self.pageControl.numberOfPages = self.pages.count
self.pageControl.currentPage = initialPage
pageViewController.view.addSubview(self.pageControl)
UIPageControle仍位于UIPageViewController的中间和底部。即使我设置了随机值,如
self.pageControl.frame = CGRect(x: 0, y: 0, width: 300, height: 200)
UIpageController位置永远不会改变
答案 0 :(得分:1)
如果要更改UIPageControl的位置。你必须写约束。我将该代码写入ViewDidLoad()
view.addSubview(pageControl)
pageControl.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
pageControl.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
pageControl.heightAnchor.constraint(equalToConstant: 60).isActive = true
pageControl.widthAnchor.constraint(equalToConstant: 30).isActive = true
我不认为你可以改变高度,但你可以创建自己的UIView或下载pods