UIPageViewController页面控制背景颜色 [英] UIPageViewController page control background color

查看:276
本文介绍了UIPageViewController页面控制背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用UIPageViewController,它运行正常。但是,它自动添加的页面控件有一个黑色背景,隐藏了当前视图控制器的底部材质(见下图)。是否可以调用UIPageViewController的页面控件并更改它的颜色?我希望页面控件显示在视图控制器上(例如,路径应用程序的演练),如设置颜色而不是黑色以清除。

i'm using UIPageViewController in my app and it's working fine. however, it's page control which has been added automatically has a black background which is hiding the current view controller's bottom material (See picture below). is it possible to call the UIPageViewController's page control and change it's color? i want the page control to be shown over the view controller (example, the Path app's walkthrough) like setting the color instead of black to clear.

推荐答案

您可以使用外观来更改UIPageControl的颜色,否则无法访问它。尝试在AppDelegate的 didFinishLaunchingWithOptions 函数中执行此操作,如下所示。

You can use appearance to change the color of UIPageControl as otherwise it is not accessible. Try doing it in your AppDelegate's didFinishLaunchingWithOptions function as given below.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIPageControl *pageControl = [UIPageControl appearance];
    pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
    pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
    pageControl.backgroundColor = [UIColor blueColor];

    return YES;
}

要仅将样式应用于特定视图控制器,您可以使用 appearanceWhenContainedIn 而不是如下:

To apply style only to a particular view controller, you can use appearanceWhenContainedIn instead as following:

UIPageControl *pageControl = [UIPageControl appearanceWhenContainedIn:[MyViewController class], nil];

UIPageControl <$中包含的对象c $ c> MyViewController 将获得这种风格。

编辑:
黑色背景屏幕底部的 UIPageControl 左右是由于 UIPageViewController的背景颜色而不是 UIPageControl 。您可以更改此颜色,如下所示:

The black background around UIPageControl at the bottom of your screen is due to the background color of your UIPageViewController not UIPageControl. You can change this color as following:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blueColor]; //Set it to whatever you like
}

这篇关于UIPageViewController页面控制背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆