yog*_*esh 3 uinavigationbar uiviewcontroller uibarbuttonitem ios
我是iOS新手,我想在我的视图控制器上添加一个导航栏,左边有2个按钮,右边是订阅.我不知道如何做到这一点.现在我刚刚从界面构建器添加了一个导航栏,在.h文件中为它创建了一个(强)refrnce并进行了编码.
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;
Run Code Online (Sandbox Code Playgroud)
但没有发生..请帮助
你可以在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;
}
Run Code Online (Sandbox Code Playgroud)