gpt4 book ai didi

swift - UIPageControl 有 tvOS 背景

转载 作者:行者123 更新时间:2023-11-30 12:38:08 24 4
gpt4 key购买 nike

在我的一款游戏中,我使用 UICollectionView 作为关卡选择菜单。我最近以编程方式向其添加了 UIPageControl。

     /// Page control
func setupPageControl() {
pageControl.hidesForSinglePage = true
pageControl.numberOfPages = DataSource.worlds
pageControl.translatesAutoresizingMaskIntoConstraints = false
pageControl.currentPageIndicatorTintColor = DataSource.pageControlColors[pageControl.currentPage]
pageControl.pageIndicatorTintColor = UIColor.white.withAlphaComponent(0.8)
pageControl.addTarget(self, action: #selector(didPressPageControl), for: .valueChanged)
view.addSubview(pageControl)

let leading = NSLayoutConstraint(item: pageControl, attribute: .leading, relatedBy: .equal, toItem: view, attribute: .leading, multiplier: 1, constant: 0)
let trailing = NSLayoutConstraint(item: pageControl, attribute: .trailing, relatedBy: .equal, toItem: view, attribute: .trailing, multiplier: 1, constant: 0)

let bottomConstant = Device.isPad ? view.frame.width / 9 : view.frame.width / 17
let bottom = NSLayoutConstraint(item: pageControl, attribute: .bottom, relatedBy: .equal, toItem: view, attribute: .bottom, multiplier: 1, constant: -bottomConstant)
view.addConstraints([leading, trailing, bottom])
}

在 iOS 上一切都很好,但在 tvOS 上,PageController 有一个半透明的背景,延伸到整个屏幕。

enter image description here

如何关闭此功能?我尝试设置 pageControl 背景颜色,但这似乎不起作用。

最佳答案

像往常一样,当我发布问题时,我会在一分钟后找到答案。

您可以通过调用此函数来删除 tvOS 上的背景

#if os(tvOS)
for subview in pageControl.subviews {
let effectView = subview as? UIVisualEffectView
effectView?.removeFromSuperview()
}
#endif

Change background color for page control

关于swift - UIPageControl 有 tvOS 背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42607964/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com