簡體   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