ios - 如何设置 Xamarin iOS 导航和状态栏颜色

标签 ios xcode xamarin.ios xamarin

我是 Xamarin iOS Designer 的新手,正在尝试设置状态栏和导航 Controller 背景颜色,如本例所示:https://www.youtube.com/watch?v=DApI7aWGNiY

我已经在 Xcode Interface Builder 中打开了我的主 Storyboard,并按照教程中的步骤将代码添加到 appDelegate.m。代码如下:

#import "AppDelegate.h"
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >>    16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary   *)launchOptions
{

[[UINavigationBar appearance] setBarTintColor:UIColorFromRGB(0x067AB5)];

return YES;
}

@end

以上内容似乎不起作用 - 当我在 Xamarin 中保存和构建时,状态和导航栏保持灰色。

我想知道为什么以及它是否与项目是在 Xamarin 而不是 Xcode 中创建的事实有关。与演示不同,我的 .m 文件位于“支持文件”文件夹中,它不包含任何自动生成的代码。 Xcode Interface Builder 上似乎有更好的文档,这就是我一直使用它而不是更新的 Xamarin iOS Designer 的原因。

Xamarin Studio 5.1.3 和 Xcode 5.1.1 有小费吗?谢谢!

**更新:通过添加能够实现状态栏和导航栏的背景颜色变化 this.NavigationController.NavigationBar.BarTintColor = UIColor.Yellow; 在 base.ViewDidLoad (); 之后添加到我的 viewcontroller.cs。仍然想知道为什么添加到 Xcode 项目 .m 文件的代码不会在 Xamarin 构建中呈现。

最佳答案

如果您想更改整个 iOS 应用程序的导航栏颜色,请将此添加到您的 AppDelegate FinishedLaunching 方法中:

UINavigationBar.Appearance.BarTintColor = UIColor.YourColor;

您还可以通过执行以下操作来编辑导航栏的文本属性:

UINavigationBar.Appearance.SetTitleTextAttributes(new UITextAttributes { TextColor = UIColor.White });

关于状态栏,如果您想将状态栏图标更改为白色而不是默认的黑色,例如,为您的导航 Controller 创建一个类并覆盖 UIStatusBarStyle

public override UIStatusBarStyle PreferredStatusBarStyle ()
{
     return UIStatusBarStyle.LightContent;
}

这适用于您的 NavigationController 及其任何子 Controller 。

关于ios - 如何设置 Xamarin iOS 导航和状态栏颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24746690/

相关文章:

iphone - 如何更改名为的 UIView 的后退按钮标题?

ios - danielgindi iOS Chart 我可以在组合图表上使用两个不同的 Yaxis 刻度吗

xcode - 更改 SearchResultsController 的顶部状态栏颜色(使用 Swift)

xamarin.ios - 单触式许可证

ios - xamarin iOS : Location Request how to find out when user clicks “Allow” or “Don' t allow” is clicked

ios - 无法通过 iOS 中的 AVPlayer 播放文档目录中的音乐?

iphone - 带有CustomUIButton的.shadowColor问题

ios - 从 Plist 中检索颜色。 iOS

c++ - 尝试编译简单测试程序时 CMake 失败

iOS Monotouch - 如何在 ViewDidLoad() 之前设置 Frame?