2016-08-24 97 views
0

我有以下代碼在textview中顯示內部圖像。我試圖顯示外部http://鏈接到textview。如何顯示外部圖像到textview?

以下代碼工作正常。請幫助我顯示外部鏈接圖像。通過這一功能,提供URL

UITextField *txtstate =[[UITextField alloc]init]; [txtstate setFrame:CGRectMake(10, 30,170, 30)]; 
txtstate.delegate=self; 

NSString * quotStr03 = [[NSString alloc] initWithFormat:@"%@",[dict valueForKey:@"deal-image"]]; 
txtstate.text=quotStr03; 
txtstate.borderStyle = UITextBorderStyleLine; 
txtstate.background = [UIImage imageNamed:quotStr03]; 
[txtstate setAutocorrectionType:UITextAutocorrectionTypeNo]; 
[self.view addSubview:txtstate]; 
+0

的[在iOS的一個URL創建一個UIImage(可能的複製http://stackoverflow.com/questions/7694215/create-a-uiimage -with-a-url-in-ios) – rmaddy

回答

0
-(UIImage *) getImageFromURL:(NSURL*) imageURL 
{ 
    NSData *imageData = [NSData dataWithContentsOfURL:imageURL]; 
    UIImage *image = [UIImage imageWithData:imageData]; 
    return image; 
} 

你會得到外部網站鏈接圖像

+1

不要在主線程中這樣做,永遠不要這樣做。 – rmaddy

+0

你是對的rmaddy –