繁体   English   中英

如何自定义导航栏?

[英]how can i customize the navigation bar?

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

遗憾的是,您正在寻找的东西并不容易实现。 所需要的技术而不是工作解决方案提醒解决方法它被称为方法调配,这里是关于如何在导航栏上应用它以获得自定义背景图像的教程: http://sebastiancelis.com/2009/ 12/21/添加-背景-图像-uinavigationbar/

向导航栏添加按钮相当容易。 假设您的导航栏被实例化为 navigationController:

UIBarButtonItem *yourButton = [[UIBarButtonItem alloc] initWithTitle:@"Hello" style: UIBarButtonStylePlain target:self action:@selector(myTargetMethodSignature:)];
navigationController.navigationItem.rightBarButtonItem = yourButton;
[yourButton release];

希望这可以帮助。 芥末

在@implementation上面添加代码in.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];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM