目前,我在我的应用程序中使用了以下代码,因为显然你不应该继承UINavigationController(如果我错了,请纠正我):
var galleryNavigation = new UINavigationController(galleryDialog);
galleryNavigation.NavigationBar.TintColor = UIColor.FromRGB (33, 114, 131);
galleryNavigation.NavigationBar.Alpha = 0.7f;
galleryNavigation.NavigationBar.Translucent = true;
我想一次定义这些样式(TintColor,Alpha等)并重复使用它们。我怎样才能做到这一点?
答案 0 :(得分:1)
如果您只想设置一些属性,而不是在AppDelegate中创建方法,或者某些共享类从每个视图控制器调用它,如
-(void)setNavigation:(UIViewController*)vc
{
//set properties here
}
否则,如果你想要更好的自定义而不是一个好的选项,那就是让 UINavigationBar 的子类在每个视图控制器中继承它
// Get our custom nav bar
MyNavigationBar* customNavigationBar = (MyNavigationBar*)self.navigationController.navigationBar;
// Set the nav bar's properties as you want like i have set its background image as
[customNavigationBar setBackgroundWith:[UIImage imageNamed:ImgNavBarBackground]];