Best approach for integrating custom graphics in iOS development - iphone

What are the best references to read (online resources or books) to read about the approaches and techniques for integrating custom images, graphics, icons for iOS apps? (What are the best strategy to manage custom images for iOS development?)

Uh, ok, not sure if you need super high level OpenGL graphics performance but if you're making ordinary iPhone apps (not games), then maybe these starter knowledge can guide you.
This is from my own limited experience but there are two types of graphics that I distinguish: graphics that are packaged with the app and graphics that are loaded through some network or file on the device.
For graphics that are packaged with the app, these tend to be the buttons and backgrounds for the look and feel of an app.
With these kind of graphics, to display an image to your application, the general idea is you create a UIImageView then add it as a subview of your View Controller's view. You then tell your image view object the image you want to display.
// create the image view object to display the image
UIImageView *myImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,100,100)];
// tell the image view object the image you want to display
[myImageView setImage:[UIImage imageNamed:#"mybutton.png"]];
// add the image view object to your view controller's view
[self.view addSubview:myImageView];
[myImageView release];
As for network images, I usually get the URL of the image I want to display, then use a image caching library such as SDWebImage to load the image like so:
NSURL *url = [[NSURL alloc] initWithString:#"http://www.mysite.com/images/myphoto.png"];
[myImageView imageWithURL:urlOfImage placeholder:[UIImage imageNamed:#"placeholder.png"]];
[url release];
How you get the URL path to your image from the network is a different matter though. If you're loading through a web service, you usually have to fetch it from the JSON or XML output.

Related

ScrollView with over 150 images crashes

I've an application which is a scrollView filled with over 150 images .. I've followed this tutorial to create it .. the application is over 550MBs and it has about 500 (150 for iPhone 5 & 150 for Retina & 150 for non-retina & buttons) photos .. The application runs very well on the simulator with no problems but on a real device when I open the application it keeps loading then a crash
so can anyone help me with this, please?
Thanks in advance.
Try to load only those images needed for displaying. ie while scrolling those images that are hidden should be taken off from the scrollview. Maybe you can make a design similar to the working of reusable UITableViewCell. ie a custom implementation for showing only the needed images and reusing them while scrolling.
There is another way, not a straight forward one, you can use a UITableView and add images to each cell and then rotate the tableview so that it will look like an horizontal scroll.
The advantage of doing this method is that the UITableView will handle all the reusability issue and we dont need to worry about. But I am not sure whether its the right way to do this.
Btw.. I have uploaded an app with the UITableView rotated horizontal scroll view to the appstore without getting rejected ;)
It is not an good way to do that ,u can upload your photo on server side and when open the app. loading the image from server.
id path = #"http://upload.wikimedia.org/wikipedia/commons/c/c7/Sholay-Main_Male_Cast.jpg";
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
imageView.image = img;
LooK at this answer

How do I texture controls on iPhone Apps?

I would like to apply a texture to my iPhone app similar to the tab bar in GameCenter.app. Is there a good tutorial somewhere that explains this? I am hoping for a method that will translate easily to other controls as well. Thanks!
A simple way to add texture for backgrounds is to use the built in colorWithPatternImage.
UIImage *image = [UIImage imageNamed:#"backgroundPattern"];
[self setBackgroundColor:[UIColor colorWithPatternImage:image]];
If you have a toolbar you should be able to use your "Patternized UIView" with UIBarButtonItem, one of its initializers take a UIView.

Memory Management

I need a clarification from all of you,That is I am implementing an iPad application. In that I tried to download and animate the images. The image count should be more than 100,000.The code I used to download and adding to the view is as follows.
UIImageView* imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0,100,100)];
NSData *receivedData=nil;
receivedData = [NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://path/prudently/iphone/image_s/e545afbf-4e3e-442e-92f9-a7891fc3ea9f/test.png"]];
imageView.image = [[UIImage alloc] initWithData:receivedData] ;
[subView addSubview:imageView];
[imageView release];
But I am getting exception after I successfully added more than 8000 image to my subview. I am getting exception at getting data from the url. And one more thing I am not releasing the subview because once I downloaded them I need to animate the subview.
Please give me your suggessions
Thank you,
Sekhar Bethalam.
100,000 images would seem a lot for desktop applications, let alone a smart phone like an iPhone. Is there not another approach you can take to solve this problem that wouldn't need such a high resource count?
You can write the URL , images or something to a cached file, and divide some pages to animate the images...
When the user press a page link , application read and animate the images of this page, images of the page which user don't use need not display.
The only way you are going to accomplish this is to dynamically create and destroy the UIImageViews as they are needed on the screen. The iPhone/iPad/iAnything are incapable of doing what you want because of the limited memory available on the device.

UIImage View + Pinch/Zoom feature when image is downloaded from web

I have a UIImageView, which pics up different images from the web, they are all different res. I have them to display as Aspect fit so that the whole picture displays even if it means leaving empty space on top or sides.
What i want to have the feature of doing is, once its displayed, to zoom in and out using the pinch or any other way.
NSURL* iURL = [NSURL URLWithString:tURL];
NSData* iData = [NSData dataWithContentsOfURL:iURL];
UIImage* iImage;
iImage = [UIImage imageWithData:iData];
FullScreenImage.image = iImage;
All this code is being executed on another thread, then it returns to the main thread and is displayed on a view using
[navigationController pushViewController:vFullscreen animated:YES];
Thanks for the help
You will need to use a UIScrollView as UIImageView does not offer any built-in zooming. See the Apple example entitled: ScrollViewSuite

Loading multiple images in sequence on iPad

I'm working on an application that talks home to a server and retrieves some data with image URL's embedded in it. I want to display those images on the view, and am getting them like so:
UIImageView *ivAvatar = [[UIImageView alloc] initWithImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.avatarUrl]]]];
[self.view addSubview:ivAvatar];
[ivAvatar release];
However, whenever data is retrieved (for example, on startup of the application), there is a delay between the retrieval of the data and the user being able to interact with the application due to the blocking nature of dataWithContentsofURL.
What is the proper way to do "Asynchronous" downloading of images? I need the UI to be responsive and load all other data that is retrieved, but load the images while allowing the UI to be responsive.
Any suggestions?
NSURL, NSURLRequest, and NSURLConnection.