Many times, we can only get URLs. Then, you need to build a uiimage.
Under normal circumstances, the. We generally through the Sdwebimage direct construction Uiimageview image, how to use the URL direct construction uiimage it?
For example, the following conversions:
NSData *data = [NSData datawithcontentsofurl:[nsurl urlwithstring:urlstr]; Button.backgroundcolor = [Uicolor colorwithpatternimage:[uiimage imagewithdata:data]];
Note: This conversion is a synchronous request and is not recommended for use in the ScrollView class
I'm going to give an asynchronous request. Implemented through multithreading
Dispatch_async (Dispatch_get_global_queue (dispatch_queue_priority_default, 0), ^{ nsdata * data = [[NSData alloc] Initwithcontentsofurl:[nsurl Urlwithstring:urlstr]]; UIImage *image = [[UIImage alloc]initwithdata:data]; if (data! = nil) { Dispatch_async (Dispatch_get_main_queue (), ^{ ///Do UI operations here (UI action must run on the main thread) });} );
IOS: UIImage by URL member