[英]iOS - Set URL image to UINavigationBar
我試圖從服務器到UINavigationBar
設置UIImage
(例如http://www.nhpdcve.org/images/b5.jpg )。
我們可以設置它的工具欄,但是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;
}
並將此Image Direct設置為yourNavigatioBar,如下所示..
[yourNavigationBar setBackgroundImage:[self getImageFromURL:yourStringURL] forBarMetrics:UIBarMetricsDefault]; //// pass your string url insted of yourStringURL
您可以輕松設置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];
你的意思是導航欄的背景? 嘗試
[yourNavigationBar setBackgroundImage:[UIImage imageNamed:@"imagename"] forBarMetrics:UIBarMetricsDefault];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.