Repeating background image in native iPhone app - iphone

Short of putting a UIWebView as the back-most layer in my nib file, how can I add a repeating background image to an iPhone app (like the corduroy look in the background of a grouped UITableView)?
Do I need to create an image that's the size of the iPhone's screen and manually repeat it using copy and paste?

Apparently a UIColor is not necessarily a single color, but can be a pattern as well. Confusingly, this is not supported in Interface Builder.
Instead you set the backgroundColor of the view (say, in -viewDidLoad) with the convenience method +colorWithPatternImage: and pass it a UI Image. For Instance:
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:#"gingham.png"]];
}
Of course, don't forget to add the image file to your application bundle.
There are also some built-in background pattern "colors":
groupTableViewBackgroundColor
viewFlipsideBackgroundColor
Because the are used globally across all iPhone apps, you incur the double-edged sword of an OS update updating the look and feel of your application (giving it a fresh new look that may or may not work right).
For instance:
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
}

You should have a look at the QuartzDemo iPhone example code from Apple, specifically QuartzImageDrawing.m. Should use the following method call.
CGContextDrawTiledImage

You can even have an animated tiled background images that move. :D
Apps Amuck has a simple tutorial that show you how to do this on their site.
31 Days of iPhone Apps - Day 16: World Tour

You should use colorWithPatternImage

Related

How to change pull to refresh icon of tableview in swift? [duplicate]

I have been looking around but couldn't find anything good about this.
I would like to customize the default UIRefeshControl with different loader, etc. So far I can only change tintColor & attributedTitle properties and most code I found are just basically creating a new "pulltorefresh" effect but what I want is to just use the UIRefreshControl and customize it a bit.
Is this possible?
You can't add different loader without accessing private APIs, but you can add background image:
UIImageView *rcImageView =
[[UIImageView alloc] initWithImage:
[UIImage imageNamed: #"refreshControl.png"]];
[self.refreshControl insertSubview:rcImageView atIndex:0];
assuming self is an instance of UITableViewController subclass.
Image size you need is 320x43px (#2x 640x86px), the middle area (approximately 35px) will be covered by the loader animation.
I show application logo there...

switch background image iphone5 - iphone4

In my FirstViewController I have write this code for switch background if device is iPhone4 or iPhone5:
Filename:
bg-for5-568#2x.png
bg-for4#2x.png
bg-for4.png
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *backgroundImage = [[UIImage alloc] init];
if([[UIScreen mainScreen]bounds].size.height == 568)
{
backgroundImage = [UIImage imageNamed:#"bg-for5-568h"];
}
else
{
backgroundImage = [UIImage imageNamed:#"bg-for4"];
}
self.view.backgroundColor = [[[UIColor alloc] initWithPatternImage:backgroundImage] autorelease];
[backgroundImage release];
}
When i lanch the app on my simulator, the background for iphone5 show double size, out of the view.
/* RESOLVED THANK YOU */
I am not sure if this is the solution for this problem as I am missing some infos, but:
At first: Strip the .png from your imageNamed: method. Since iOS4, you shouldn't do this anymore. The next thing is: What are the Names of your image? Note that an iPhone5 has a retina display, and your image should be named bg-for5-568h#2x.png but referred in the sourcecode as bg-for5-568h.
Besides that: In almost every case where your image isn't a photograph, what you are doing is a bad idea. And even if it is a photograph, simply use the bigger image for the iPhone 4 and 4S as well. It's not that much bigger, so the memory footprint isn't a problem here! Have a look on UIImageView's contentMode property. You can use this to adjust the position of the larger image. You also might want to check UIImageViews clipSubviews property to clip the image if it isn't fullscreen.
Trust me, in my company we had a loot of hooks for stuff like ~ipad, ~iphone, ~2x and even stretchable images. And all these hooks worked fine till the date, apple announced something similar or simply a new device. So I decided to not do these kind of hooks anymore. They seem to be very helpful in the first place, but the trouble you get when there is something new on the market isn't worth it!
You should append #2x suffix to all of your retina images.
In your case your image should be stored as "bg-for5-568h#2x.png".
Hope it will resolve the issue.
I would not advise doing this, what if Apple change their screensize again and you have to go back and rewrite all your code?
A simple fix is to use:
self.view.backgroundColor = [UIColor colorWithPatternImage:/* your image*/];
This could give you some issues with stretching or tiling.
I prefer using
UIImage* imageName = [[UIImage imageNamed:/*image name*/]resizableImageWithCapInsets:UIEdgeInsetsMake(top,left,bottom,right)];
In iOS 6 you can improve this further by defining if you want the image to stretch or tile. This allows you to create a border which won't change and then the centre of your image by default being tiled and filling the space of your imageview

Best approach for integrating custom graphics in iOS development

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.

Which UI object to do this?

I have seen many times waiting panels (panels with a uiactivityindicatorview) black/dark with some transparency and white labels.
Like this one :
I guess it is a standard element.
Where can I find it?
Try This. it's the best solution I came across to show the activity. MBProgressHUD
MBProgressHUD looks nice. You might want to check out http://code.google.com/p/toast-notifications-ios/ too.
There's no iOS component that does this.
If you don't want to include an external library just for this one component then you can do it using UI components.
/* Warning, typed from memory */
// Create the UIView that's the background
UIView *pleaseWaitView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 80)];
[pleaseWaitView setBackgroundColor:[UIColor colorWithWhite:0.5 alpha:0.5]];
[[pleaseWaitView layer] setCornerRadius:5.0f];
// And create an activity indicator
UIActivityIndicator *i = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[i startAnimating];
[pleaseWaitView addSubview:i];
[i release];
// Add it to the main view (in the middle)
[pleaseWaitView setCenter:CGPointMake(self.view.bounds.size.width/2, self.view.bounds.size.height/2)];
[self.view addSubview:pleaseWaitView];
You can add a UILabel with whatever text you want (in your case, 'Authenticating') in the same way as you added the activity indicator.
The tricky part is setting the corner radius - you will probably need this at the top of your .m file :
#import <QuartzCore/QuartzCore.h>
NB You can do this in interface builder as well if you want (apart from the corner radius bit!) ;)
I answered a question that included an overlay like this. I included the code and the overlay image you need to do it with. Take a look at this answer and take a look at the screen shot it created. I use this overlay as I send email in the background so you will want to edit the code to do your function but the overlay code is already in place.
Locking the Fields in MFMailComposeViewController
Happy Coding!
Check out DSActivityView. I've successfully used it in a few of my projects.
As by now there is no standard UIElement for that in iOS.
But checkout this library:

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.