如何自定义导航栏或在其中添加背景图像和导航栏按钮? 请以简单的方式告诉我不要让答案难以理解我不是专家吗? 一步一步解释。
答案 0 :(得分:0)
你遗憾地寻找的并不容易。该技术需要提醒工作解决方案而不是工作解决方案它称为方法调配,这是一个如何在导航栏上应用它以获取自定义背景图像的教程:http://sebastiancelis.com/2009/12/21/adding-background-image-uinavigationbar/
向导航栏添加按钮非常简单。假设您的导航栏已实例化为navigationController:
UIBarButtonItem *yourButton = [[UIBarButtonItem alloc] initWithTitle:@"Hello" style: UIBarButtonStylePlain target:self action:@selector(myTargetMethodSignature:)];
navigationController.navigationItem.rightBarButtonItem = yourButton;
[yourButton release];
希望这会有所帮助。 芥末
答案 1 :(得分:0)
请遵循本教程:How do iPhone apps Instagram/Reeder/DailyBooth implement custom NavigationBars with variable width back buttons?。它包含一个源代码示例。
答案 2 :(得分:-2)
- (void)drawRect:(CGRect)rect {
/ UIImage *image = [UIImage imageNamed: @"navigation_bar.png"];
UIImage *image = [UIImage imageNamed: @"navigationbarnew2.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, 44)];
}
@end
UIImage* image3 = [UIImage imageNamed:@"mail-48_24.png"];
CGRect frameimg = CGRectMake(0, 0, image3.size.width, image3.size.height);
UIButton *someButton = [[UIButton alloc] initWithFrame:frameimg];
[someButton setBackgroundImage:image3 forState:UIControlStateNormal];
[someButton addTarget:self action:@selector(sendmail)
forControlEvents:UIControlEventTouchUpInside];
[someButton setShowsTouchWhenHighlighted:YES];
mailbutton =[[UIBarButtonItem alloc] initWithCustomView:someButton];
self.navigationItem.rightBarButtonItem=mailbutton;
[someButton release];