自定义UIBarButtonItem与接口生成器

问题描述:

我用pushViewController:动画:方法在UIViewController去B UIViewController,并且两个UIViewController有selfs xib文件。自定义UIBarButtonItem与接口生成器

在系统默认情况下,我不需要改变任何东西,我可以从B UIViewController返回一个UIViewController。

但我想定制我的后退按钮,我用像后续代码解决方案:

- (void)initBarButton { 
    UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleDone target:self action:@selector(cancel)]; 

    self.navigationItem.leftBarButtonItem = cancelButton; 

    UIBarButtonItem *updateButton = [[UIBarButtonItem alloc] initWithTitle:@"Update" style:UIBarButtonItemStyleDone target:self action:@selector(save)]; 

    self.navigationItem.rightBarButtonItem = updateButton; 
} 

- (void)cancel { 
    [self.navigationController popViewControllerAnimated:YES]; 
} 

就像这一点,但我想改变,在Interface Builder中修改了厦门国际银行文件,要做到这一点。我尝试使用这样的:

enter image description here

但系统默认的导航栏盖,当我隐藏系统默认条,滑动手势(回去喜欢流行的行动)也将被删除。

是否有任何可能的方法来做我想要的?

顺便说一句,我用自动布局的界面生成器中的导航栏,我怎么能让它看起来像这样的系统默认导航栏(填补状态栏差距)?

enter image description here

是否有任何真正的原因以编程方式做到这一点?看起来你应该能够完成你想要做的所有事情。

+0

在某些情况下,我不想使用故事板,所以我想知道这一点。 –

马库斯吴如果您想使用厦门国际银行,而不是故事板为实现这一点,你可以看到下面的步骤

1.Remove the storyboard from the project 
2.Also delete the Main from Main Interface of Deployment Target of Project Target. 
3.Now create the New User Interface(View or Empty) and give name as ViewController 
4.Then click the Placeholder File Owner with right side Identity Inspector 
5.In identity Inspector Custom Class -> Class ->Click the drop down and choose the ViewController. 
6.Then Click right side connections inspector. 
7.Click the empty circel(name is View) in Outlet.Drag this to the view.I mean you need to press control+emptycircle and drag it to the View. 

8.in appDelegate.h 
    Import - #import "ViewController.h" 
    @property (strong, nonatomic) ViewController *vc; 

9.In appDelegate.m 
    @synthesize vc; 
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
    { 
     // Override point for customization after application launch. 
     self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]]; 
     vc = [[ViewController alloc]initWithNibName:@"ViewController" bundle:nil]; 
     UINavigationController *navigationVC = [[UINavigationController alloc]initWithRootViewController:vc]; 
     navigationVC.navigationBarHidden = YES; 
     self.window.rootViewController = navigationVC; 
     self.window.backgroundColor = [UIColor clearColor]; 
     [self.window makeKeyAndVisible]; 
     return YES; 
    } 

10.Now in xib create the custom button Back programmatically or from objects(drag button and give connection) 

如果你用故事板,你只需要取消选中的节目导航栏。

1.First Click NavigationController in stroyboard 
2.Click the Attributes Inspector of Right side 
3.Then Click Navigation Controller 
4.Inside the Navigation Controller 
    UnTick the Bar Visibility - Shows Navigation Bar 
5.Now create the custom button programmatically or drag it from the Object Library to ViewController in XIB