Change background color for page control

前端 未结 3 1804
甜味超标
甜味超标 2021-01-28 12:54

Is there any way to change background color of page control in tvOS?

NOTE: i want to set background color as clear color

I hav

相关标签:
3条回答
  • 2021-01-28 13:37

    @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];
        }
    }
    
    0 讨论(0)
  • 2021-01-28 13:37

    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
    }
    
    0 讨论(0)
  • 2021-01-28 13:43

    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()
      }
    }
    
    0 讨论(0)
提交回复
热议问题