2011-11-27 101 views
1

我正在尝试使用MonoTouch编写应用程序。我需要设置导航栏的背景颜色。我想将它设置为橙色。这似乎是一件容易的事情,但我似乎无法让它工作。目前,我在AppDelegate.cs文件中执行以下操作:单点触摸设置导航栏颜色

this.window = new UIWindow (UIScreen.MainScreen.Bounds); 
this.rootNavigationController = new UINavigationController(); 

UIColor backgroundColor = new UIColor(74, 151, 223, 255); 
this.rootNavigationController.NavigationBar.BackgroundColor = UIColor.Orange; 

但是,导航栏颜色仍然是默认颜色。如何设置导航栏的背景颜色?

+0

下面的代码不会做你所期望的:'new UIColor(74,151,223,255)',因为.ctor接受'float',而不是字节。如果你想使用'byte'来创建你的颜色,请尝试使用'UIColor.FromRGBA'。 – poupou

回答

1

尝试更改TintColor和Translucent属性。

6

为罗布使用TintColor属性描述你可以这样做一个特设的基础上:

this.rootNavigationController.NavigationBar.TintColor = UIColor.Orange; 

另外,您还可以设置TintColor所有UINavigationBars一次使用UIAppearance代理iOS 5中。这通常是做某处附近DidFinishLaunchingWithOptions方法在AppDelegate中:

UINavigationBar.Appearance.TintColor = UIColor.Orange; 

您可以检查出苹果的文档更详细的信息和执行的限制:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIAppearance_Protocol/Reference/Reference.html

+0

似乎并非monotouch中的所有视图都支持TintColor属性。 – slott