Ios 在视图控制器上添加导航栏
我是iOS新手,我想在我的视图控制器上添加一个导航栏,左侧有2个按钮,右侧有订阅。我不知道怎么做。到目前为止,我刚刚从interface builder中添加了导航条,在.h文件中为它创建了一个(强)引用,并进行了以下编码Ios 在视图控制器上添加导航栏,ios,uiviewcontroller,uinavigationbar,uibarbuttonitem,Ios,Uiviewcontroller,Uinavigationbar,Uibarbuttonitem,我是iOS新手,我想在我的视图控制器上添加一个导航栏,左侧有2个按钮,右侧有订阅。我不知道怎么做。到目前为止,我刚刚从interface builder中添加了导航条,在.h文件中为它创建了一个(强)引用,并进行了以下编码 navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 20, 1026, 50)]; [navBar setTintColor:[UIColor clearColor]]; [navBar setBack
navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 20, 1026, 50)];
[navBar setTintColor:[UIColor clearColor]];
[navBar setBackgroundColor:[UIColor redColor]];
[navBar setDelegate:self];
[self.view addSubview:navBar];
UIBarButtonItem *bi1 = [[UIBarButtonItem alloc] initWithTitle:@"subscribe" style:UIBarButtonItemStyleBordered target:self action:@selector(editBotton)];
bi1.style = UIBarButtonItemStyleBordered;
bi1.tintColor =[UIColor colorWithWhite:0.305f alpha:0.0f];
self.navigationItem.rightBarButtonItem = bi1;
但是什么都没有发生。。请帮助我认为您必须学习有关UINavigationController的基本概念。您可以从以下教程中学习:
您可以在AppDelegate中添加
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone"
bundle: nil];
SampleViewController *mainViewController = (SampleViewController*)[mainStoryboard
instantiateViewControllerWithIdentifier: @"SampleViewController"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:mainViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:navigationController];
[self.window setBackgroundColor:[UIColor whiteColor]];
[self.window makeKeyAndVisible];
return YES;
}
用这个