【发布时间】:2013-05-24 06:53:02
【问题描述】:
我想在导航栏中添加一张图片。它应该贯穿我的应用程序。它应该被添加到所有导航控制器中。
任何帮助将不胜感激。
【问题讨论】:
标签: iphone ios objective-c uiimageview uinavigationbar
我想在导航栏中添加一张图片。它应该贯穿我的应用程序。它应该被添加到所有导航控制器中。
任何帮助将不胜感激。
【问题讨论】:
标签: iphone ios objective-c uiimageview uinavigationbar
试试这个,
UINavigationBar *navBar = self.navigationController.navigationBar;
UIImage *image = [UIImage imageNamed:@"image.png"];
[navBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
【讨论】:
您可以使用以下代码添加图像..
UIImage *image = [UIImage imageNamed: @"yourImageName.png"];
UIImageView *imgView = [[UIImageView alloc] initWithImage: image];
self.navigationItem.titleView = imgView;
【讨论】:
if ([[UINavigationBar class] respondsToSelector:@selector(appearance)])
{
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imageName ofType:@"png"]] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
UITextAttributeTextColor,
[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],
UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
UITextAttributeTextShadowOffset,
[UIFont fontWithName:@"HelveticaNeue-Bold" size:18.0],
UITextAttributeFont,
nil]];
}
将其放入您的 Appdelegate.m
【讨论】:
你使用这个代码:
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"Image.png"] forBarMetrics:UIBarMetricsDefault];
【讨论】:
我是一个理想的,因为我有这样的问题,所以你可以试试我的方法,ok!!
首先,您创建一个导航控制器,然后将其显示在窗口中
UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:YourView];
下一步:您创建一个具有图像属性的对象 Uiimageview 与您想要添加导航栏的图像和框架 ptoperty 是您想要的位置
UIImageView *imgView=[UIImageView alloc] initWithImage:[UIImage imageNamed:@"YourImagename"];
imgView.Frame=CGrectmake();
最后一步:在导航栏中添加对象 imgView 作为子视图
[nav.navigationBar addSubview:imgView];
完成!!!!!!!!!!
【讨论】: