我的页面控件 UI 没有更新?
My Page Control UI is not getting updated?
我的页面控件 UI 没有更新。页面控制号每次都在更新,但在页面控制 UI 中没有更新。我想也许使用 updateCurrentPageDisplay 会起作用,或者这就是我所缺少的,但我刚刚收到一个错误。这是我的代码。我是否遗漏了需要更新 UI 的内容?
@IBOutlet weak var pageControl: UIPageControl!
override func viewDidLoad() {
super.viewDidLoad()
collection.delegate = self
collection.dataSource = self
thisWidth = CGFloat(collection.frame.width)
pageControl.hidesForSinglePage = true
pageControl = UIPageControl.appearance()
pageControl.pageIndicatorTintColor = UIColor.lightGray
pageControl.currentPageIndicatorTintColor = UIColor.red
pageControl.numberOfPages = 10
pageControl.currentPage = 0
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 10
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! CalanderCollectionViewCell
let imagePath = array[indexPath.section]
cell.configureCell(properties: imagePath)
return cell
}
func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
self.pageControl.currentPage = indexPath.section
print("current page\(pageControl.currentPage)")
pageControl.updateCurrentPageDisplay()
print(indexPath.section)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
thisWidth = CGFloat(collection.frame.width)
return CGSize(width: thisWidth, height: collection.frame.height)
}
删除这一行:
pageControl = UIPageControl.appearance()
我的页面控件 UI 没有更新。页面控制号每次都在更新,但在页面控制 UI 中没有更新。我想也许使用 updateCurrentPageDisplay 会起作用,或者这就是我所缺少的,但我刚刚收到一个错误。这是我的代码。我是否遗漏了需要更新 UI 的内容?
@IBOutlet weak var pageControl: UIPageControl!
override func viewDidLoad() {
super.viewDidLoad()
collection.delegate = self
collection.dataSource = self
thisWidth = CGFloat(collection.frame.width)
pageControl.hidesForSinglePage = true
pageControl = UIPageControl.appearance()
pageControl.pageIndicatorTintColor = UIColor.lightGray
pageControl.currentPageIndicatorTintColor = UIColor.red
pageControl.numberOfPages = 10
pageControl.currentPage = 0
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 10
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! CalanderCollectionViewCell
let imagePath = array[indexPath.section]
cell.configureCell(properties: imagePath)
return cell
}
func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
self.pageControl.currentPage = indexPath.section
print("current page\(pageControl.currentPage)")
pageControl.updateCurrentPageDisplay()
print(indexPath.section)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
thisWidth = CGFloat(collection.frame.width)
return CGSize(width: thisWidth, height: collection.frame.height)
}
删除这一行:
pageControl = UIPageControl.appearance()