我该如何自定义导航栏?

时间:2011-04-28 10:18:01

标签: iphone objective-c ios4

如何自定义导航栏或在其中添加背景图像和导航栏按钮? 请以简单的方式告诉我不要让答案难以理解我不是专家吗? 一步一步解释。

3 个答案:

答案 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)

答案 2 :(得分:-2)

在@implementation

上面的.m文件中添加代码
- (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

要向导航栏添加按钮,请在viewdidload

中添加以下代码
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];