2013-05-04 103 views
-1

我有一個NSMutableArray它存儲URL到圖像。而這個NSMutableArray被稱爲userPic。從我的服務器它只打印出網址:不是JSON或任何東西,只有網址。iPhone NSMutableArray從url加載背景圖像

我可以看到在Xcode的輸出,它顯示的網址,但如何獲得此URL在userPic背景?我試圖添加與視圖圖像的背景。

如果有什麼不清楚,對此感到抱歉。請讓我知道。

+0

使用[NSData的dataWithContentsOfURL:]你可以從網址獲取圖像數據,然後需要分配給物業圖像配OT的UIImageView – HarshIT 2013-05-04 10:58:22

+0

感謝的答案,但你可以給我一個例子嗎? :) – MariusD 2013-05-04 11:07:54

+0

http://stackoverflow.com/questions/6811640/loading-image-from-url-on-iphone可以幫助你。 – 2013-05-04 11:09:49

回答

1

請嘗試使用這一個。我認爲你的URL在你的數組的索引0。

NSURL *imgURL = [NSURL URLWithString:[userPic objectAtIndex:0]]; // put your particular index where your image url in your array... 
NSData *imgData = [[NSData alloc]initWithContentsOfURL:imgURL]; 
UIImage *img = [UIImage imageWithData: imgData]; 

[newView setBackgroundColor:[UIColor colorWithPatternImage:img]] 
+0

即時嘗試您的代碼,我沒有得到任何錯誤。所以謝謝:) – MariusD 2013-05-04 11:36:51

+0

不能對不起。需要更多的聲譽。 – MariusD 2013-05-04 11:40:14

+0

K親愛的........我會試試.. – 2013-05-04 11:49:48