0

目前,我在整个应用程序中重复使用以下代码,因为显然您不应该继承 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 等)并重用它们。我怎样才能做到这一点?

4

1 回答 1

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]];
于 2012-10-15T07:17:43.097 回答