How do I make the bottom bar with dots of a UIPageViewController translucent?

前端 未结 12 1898
逝去的感伤
逝去的感伤 2020-12-04 07:37

I\'m in the process of making a tutorial, and I\'m trying to emulate the style of Path\'s tutorial like so:

http://www.appcoda.com/wp-content/uploads/2013/06/UIPageV

12条回答
  •  暖寄归人
    2020-12-04 08:17

    The same effect can be achieved simply by subclassing UIPageViewController and overriding viewDidLayoutSubviews as follows:

    -(void)viewDidLayoutSubviews {
        UIView* v = self.view;
        NSArray* subviews = v.subviews;
        // Confirm that the view has the exact expected structure.
        // If you add any custom subviews, you will want to remove this check.
        if( [subviews count] == 2 ) {
            UIScrollView* sv = nil;
            UIPageControl* pc = nil;
            for( UIView* t in subviews ) {
                if( [t isKindOfClass:[UIScrollView class]] ) {
                    sv = (UIScrollView*)t;
                } else if( [t isKindOfClass:[UIPageControl class]] ) {
                    pc = (UIPageControl*)t;
                }
            }
            if( sv != nil && pc != nil ) {
                // expand scroll view to fit entire view
                sv.frame = v.bounds;
                // put page control in front
                [v bringSubviewToFront:pc];
            }
        }
        [super viewDidLayoutSubviews];
    }
    

    Then there is no need to maintain a separate UIPageControl and such.

提交回复
热议问题