Change background color for page control

。_饼干妹妹 提交于 2019-12-02 10:48:36

This transparent background is a subview in UIPageControl of type UIVisualEffectView. You could remove it like this:

for subview in pageControl.subviews {
  if subview.isKindOfClass(UIVisualEffectView) {
    subview.removeFromSuperview()
  }
}

@alexander-johmann above has a solution (though I'd like to find another way).

Ideally it would be better to be able to set the actual background color. This solution doesn't really do that; it removes elements of the UIPageControl to get the 'effect' of providing a clear background without actually doing so.

Here is an objective-c version of the same code:

for (UIView *subview in pageControl.subviews) {
    if ([subview isKindOfClass:[UIVisualEffectView class]] == YES) {
        [subview removeFromSuperview];
    }
}

The fix Alexander mentioned didn't work for me when too many pages had to be displayed. I would rather set the effect to nil:

for subview in pageControl.subviews {
    guard let effectView = subview as? UIVisualEffectView else { continue }
    effectView.effect = nil
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!