Iphone iOS-将URL图像设置为UINavigationBar
Iphone iOS-将URL图像设置为UINavigationBar,iphone,ios,ipad,uiimage,uinavigationbar,Iphone,Ios,Ipad,Uiimage,Uinavigationbar,我正在尝试将UIImage(例如)从服务器设置为UINavigationBar 我们可以将其设置为工具栏,但如何将UINavigationBar?作为导航栏的背景? 试一试 您可以使用下面的方法设置图像 [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"yourImageName"] forBarMetrics:UIBarMetricsDefault]; 还可以使用下面的方法从UR
我正在尝试将
UIImage
(例如)从服务器设置为UINavigationBar
我们可以将其设置为工具栏,但如何将
UINavigationBar
?作为导航栏的背景?
试一试
您可以使用下面的方法设置图像
[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;
}
并将此图像直接设置为导航条,如下图所示
[yourNavigationBar setBackgroundImage:[self getImageFromURL:yourStringURL] forBarMetrics:UIBarMetricsDefault]; //// pass your string url insted of yourStringURL
您可以轻松设置
导航栏的图像。
如果希望图像分辨率清晰,则图像大小必须为320 x 45
设置图像,如下代码所示:-
按如下方式设置资源文件夹中的图像:-
UIImage *image = [UIImage imageNamed:@"navBarLoc.png"];
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
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];
您也可以这样设置URL中的图像:-
UIImage *image = [UIImage imageNamed:@"navBarLoc.png"];
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
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];
如果有人回答你的问题,你必须做出回应(感谢Nitin和Paras(也为编辑问题和答案)。它的图片来自url,而不是捆绑。