我正在尝试将UIImage
(例如http://www.nhpdcve.org/images/b5.jpg)从服务器设置为UINavigationBar
.
我们可以设置它的工具栏,但是呢UINavigationBar
?
问问题
288 次
3 回答
1
您可以使用以下方法设置图像
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"yourImageName"] forBarMetrics:UIBarMetricsDefault];
还使用以下方法从 URL 获取图像..
-(UIImage *) getImageFromURL:(NSString *)fileURL {
UIImage * result;
NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:fileURL]];
result = [UIImage imageWithData:data];
return result;
}
并将此图像直接设置为 yourNavigatioBar,如下所示。
[yourNavigationBar setBackgroundImage:[self getImageFromURL:yourStringURL] forBarMetrics:UIBarMetricsDefault]; //// pass your string url insted of yourStringURL
于 2012-11-05T11:58:13.010 回答
1
您可以轻松设置Navigationbar
. 如果您想图像分辨率清晰,那么您的图像大小必须320 x 45
设置为如下代码所示的图像:-
像这样从资源文件夹设置图像:-
UIImage *image = [UIImage imageNamed:@"navBarLoc.png"];
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
您还可以像这样从 URL 设置图像:-
NSURL *url =[NSURL URLWithString:@"http://www.urimageur/com"];
NSData *d =[NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:d];
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
于 2012-11-05T12:09:11.613 回答
0
你的意思是作为导航栏的背景?尝试
[yourNavigationBar setBackgroundImage:[UIImage imageNamed:@"imagename"] forBarMetrics:UIBarMetricsDefault];
于 2012-11-05T11:57:53.680 回答