xcode 更改 UIPageViewController 自己的 PageController 关于点的颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17684922/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Changing UIPageViewController own PageController regarding Color of Dots
提问by Lightbarrier
Hey I'm using a UIPageViewController to control what page I am on and for scrolling. I know it's possible to show a Page Controller along with it by simply adding the following two functions.
嘿,我正在使用 UIPageViewController 来控制我所在的页面和滚动页面。我知道可以通过简单地添加以下两个函数来显示页面控制器。
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
What I want to know is if it's possible to change the color of the page controller, so the dots are more visible on the background I'm using?
我想知道的是是否可以更改页面控制器的颜色,以便我使用的背景上的点更明显?
I know a regular page controller has the properties:
我知道常规页面控制器具有以下属性:
@property(nonatomic,retain) UIColor *currentPageIndicatorTintColor
@property(nonatomic,retain) UIColor *pageIndicatorTintColor
However, I can't figure out for the life of me how to access these properties or the Page Controller for that matter from UIPageViewController.
但是,我终生无法弄清楚如何从 UIPageViewController 访问这些属性或页面控制器。
It might be helpful, if someone just said how to change the properties in general?
如果有人只是说一般如何更改属性,这可能会有所帮助?
回答by Pasi Heikkinen
You can use UIAppearance to configure UIPageControl colors. This applies to UIPageControls in UIPageViewControllers too.
您可以使用 UIAppearance 来配置 UIPageControl 颜色。这也适用于 UIPageViewControllers 中的 UIPageControls。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIPageControl *pageControl = [UIPageControl appearance];
pageControl.pageIndicatorTintColor = [UIColor whiteColor];
pageControl.currentPageIndicatorTintColor = [UIColor redColor];
}
回答by Hellojeffy
If you would like to change the UIPageControl's colors for a specific UIPageViewController, you can use the following:
如果您想更改特定 UIPageViewController的 UIPageControl 颜色,可以使用以下命令:
In Swift 3
在斯威夫特 3
let pageControl: UIPageControl = UIPageControl.appearance(whenContainedInInstancesOf: [MyPageViewController.self])
pageControl.pageIndicatorTintColor = UIColor.green
// ... any other changes to pageControl
回答by Imanou Petit
UIPageControl
conforms to UIAppearance
protocol. The Apple Developper API Referencestates about UIAppearance
:
UIPageControl
符合UIAppearance
协议。Apple Developper API Reference说明UIAppearance
:
Use the
UIAppearance
protocol to get the appearance proxy for a class. You can customize the appearance of instances of a class by sending appearance modification messages to the class's appearance proxy.
使用
UIAppearance
协议获取类的外观代理。您可以通过向类的外观代理发送外观修改消息来自定义类实例的外观。
Therefore, using Swift 2.2, you may set UIPageControl
's pageIndicatorTintColor
and currentPageIndicatorTintColor
in a subclass of UINavigationController
or in your AppDelegate
class (for a more global approach).
因此,使用 Swift 2.2,您可以在您的类的子类或类中设置UIPageControl
'spageIndicatorTintColor
和(对于更全局的方法)。currentPageIndicatorTintColor
UINavigationController
AppDelegate
CustomNavigationController.swift:
CustomNavigationController.swift:
class CustomNavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
// Set pageIndicatorTintColor and currentPageIndicatorTintColor
// only for the following stack of UIViewControllers
let pageControl = UIPageControl.appearance()
pageControl.pageIndicatorTintColor = UIColor.blueColor()
pageControl.currentPageIndicatorTintColor = UIColor.greenColor()
}
}
AppDelegate.Swift:
AppDelegate.Swift:
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Set pageIndicatorTintColor and currentPageIndicatorTintColor globally
let pageControl = UIPageControl.appearance()
pageControl.pageIndicatorTintColor = UIColor.blueColor()
pageControl.currentPageIndicatorTintColor = UIColor.greenColor()
return true
}
}