0
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:self.viewController];

// CHANGE COLOR TO BLACK

nav.navigationBar.tintColor = [UIColor blackColor];

// ADDING IMAGE TO NAVIGATION BAR
UIImage *image = [UIImage imageNamed:@"logo_36.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[nav.navigationBar.topItem setTitleView:imageView];

self.window.rootViewController = nav;
[self.window makeKeyAndVisible];  

return YES;
}

我已经在 appdelegate 类中尝试过这段代码,因为我想要在整个项目中使用它,它适用于显示图像,但它显示在中心也我需要我无法显示的文本。

请有人建议我如何在iOS导航栏的左侧显示图像和文本

4

1 回答 1

-1

为什么要将 imageview 设置为导航 topItem titleview

代替

[nav.navigationBar.topItem setTitleView:imageView];

使用nav.navigationbar.topItem.leftBarButtonItem:imageview

并设置 `[nav.navigationBar.topItem setTitle:@"text you want"];

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];

UIBarButtonItem *mailbutton =[[UIBarButtonItem alloc] initWithCustomView:someButton];
self.navigationItem.leftBarButtonItem=mailbutton;
[someButton release];
于 2013-08-30T11:01:15.160 回答