//AppDelegate.m中设置背景图片
self.rootNavigationController.navigationBar.barStyle = UIBarStyleBlackOpaque; [self.rootNavigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"NavigationBg"] forBarMetrics:UIBarMetricsDefault];
/自定义NavigationItem
- (void)setNavigationItem { NSMutableArray * leftBarButtonItems = [[NSMutableArray alloc] initWithCapacity:0]; UIImage * logoImage = [UIImage imageNamed:@"nav_logo"]; UIImageView * imageView = [[UIImageView alloc] initWithImage:logoImage]; imageView.frame = CGRectMake(10, 7, 30, 30); UIBarButtonItem * imageItem = [[UIBarButtonItem alloc] initWithCustomView:imageView]; [leftBarButtonItems addObject:imageItem]; [self.navigationItem setLeftBarButtonItems:leftBarButtonItems]; UIButton *searchButton = [UIButton buttonWithType:UIButtonTypeCustom]; searchButton.frame = CGRectMake(275, 7, 30, 30); [searchButton setBackgroundImage:[UIImage imageNamed:@"search"] forState:UIControlStateNormal]; [searchButton addTarget:self action:@selector(doSearch:) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:searchButton]; [self.navigationItem setRightBarButtonItem:rightBarButtonItem]; //设置返回键 UIImage *backButtonHomeImage = [[UIImage imageNamed:@"nav_back"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 30, 0, 0)]; [[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonHomeImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; self.title =@" "; }
自定义Navigation
最新推荐文章于 2024-06-04 14:59:05 发布