iphone-uiview-background - iphone

I am new to iPhone development. I have one XIB file, the login page (a form).
Now I want to set the UIView background image.
When I supply an image from Interface Builder then there is no effect, and when I set it from the code then also no effect.
self.view.backgroundColor = [UIColor colorWithPatternImage:
[UIImage imageNamed:#"srk_ipad_Homepg.png"]];
I don't want to use a UIImageView because when I place an image, all my controls are hidden behind the UIView.

You can use UIImageView to set a background without harm, you just have to move it to the top of the view hierarchy. Look at this splashscreen view:
And this is the view's hierarchy tree:
This will prevent your controls from being covered.

Related

UINavigationController - Keep Background Image Across All Views

Is there a way to have a background image remain constant across all views in a navigation controller? Currently I am loading the same background in each view's viewDidLoad method but this shows the background image move when navigating from view to view. I'd rather just the content of the view infront of the background "slide" on/off screen, but the background stay stationary. This is my current background image loading code:
UIImageView *background = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
background.image = [UIImage imageNamed:#"InfoBackground.png"];
[self.view addSubview:background];
[self.view sendSubviewToBack:background];
[background release];
Thanks!
Hm, perhaps if you look at the documentation (scroll down to Figure 2) you will get an idea of what you're dealing with. Because you are setting the background image for each of your view controllers that are being pushed into the UINavigationController, you will get that animation. What you need to do is set the background image into the nav controller itself.
I believe myNavController.view insertSubview:myImageView atIndex:0 should work. If your image needs to fill in behind the content view exactly, you could set the frame coordinates based on the coordinates and/or heights of the navbar and toolbar, which can be accessed through the navigation controller's properties. If not, just set the frame to the superview's bounds.
Let me know how it goes.
Edit: Oh, note that you would need to make sure each of your view controllers had transparent backgrounds.
i think the better idea is place background image on window and set all view's(all viewcontroller's view) background color to clear color [UIColor clearColor].
if you want background image static then there is only one way but i don't know that is possible or not, If we put image in window and make navigation controller transparent then it's stay static whatever you will do. because we are not changing window while push or pop.
I am just suggesting try this way i haven't tried like this.

Adding Background Image to FlowCover

I'm using FlowCover in an app and need to add a background, but inserting a UIImageView and sending to the back in .xib only gives me the background image and buttons and no coverflow animation. I also cannot see where i would programme a
self.backgroundColor = [[UIColor alloc]initWithPatternImage:[UIImage imageNamed:#"bground.png"]];
type thing in the implemetation.
Any clues?
It does appear that you can add an UIImageview to the ViewController's View in the MainWindow.nib:
In the editor dropdown you can send the image to the back. It means that the Flow Cover View MUST NOT be set to Opaque and then will sit on top of the ImageView.

How to set this Layout in iPhone need Some help

I have Implement Some paint like application. For that the Layout is like as below:
Here, there is One View and two buttons. In My application i am selecting the colour from Button2 and then doing drawing on View.
But the Problem is while i am selecting the Colour and if i do the Paint on the View, all works file but if that paint come over the Button1, it also paint on that button1. I want set as like that the selection colour Should not be paint on the Button1 and only paint on the View.
So for that What Should i have to do ?
I want to set the Button1 in front of the View and do not allow to paint on it.
please Guide me proper regarding this mater.
Thanks.
You have to make sure your buttons are not subviews of the view you are drawing in.
The simplest way to do this is to organize your buttons and your view in interface builder so that you have a UIView within your window as well as your buttons which must be on a higher layer than your UIView but cannot be inside your UIView. I would post pictures if the site would let me. You will then need to make a UIView IBOutlet to attatch to the UIView in Interface Builder and to draw to in your code.
To do this programmatically, after you have created your buttons, create a UIView and add it as a subview to your viewController's view by using (if myView is your UIView)
[self.view addSubview:myView]
and then use
[self.view send SubviewToBack:myView]
to make sure it is behind your other subviews (your buttons). Draw to myView and it should appear behind the buttons.

How to scroll the content without scrolling the image in the background using UIScrollView?

I am trying to scroll the content without scrolling the image in the background using UIScrollView.
I am using IB and setting the FileOwner View to point to the Scroll View (Image View is a child of the Scroll view). I have made the image height to be 960 pixels.
I have also set scrolling content size in the vierController that owns this UIView
(void)viewDidLoad {
UIScrollView *tempScrollView = (UIScrollView *)self.view;
tempScrollView.contentSize=CGSizeMake(320, 960);
}
My problem is that the Image only appears moves along with the content.
I have tried taking out the settings in viewDidLoad, but the scrolling cease to function.
I have also tried changing the location of the image and have it placed under VIEW instead of Scoll View (by the way Scroll View is a child of VIEW), but that resulted in the app breaking (termination error).
Any advice would be appreciated.
The easiest (and correct way) is to set an background image to your UIScrollView
UIImage *img = [UIImage imageNamed:#"image.png"];
[scrollView setBackgroundColor:[UIColor colorWithPatternImage:img]];
The easiest way is to set an UIImageView behind your UIScrollView(UIImageView and UIScrollView under UIView) and make your UIScrollView background color as clear color as mentioned by Janson. By this way you can scroll the content without scrolling the image in the background using UIScrollView.
Thanks. This was extremely helpful.
The one thing that I would add (pardon if it is obvious, but for people new to the platform (i.e., me), it took a bit of playing around).
I put the code from "unset"'s example after where I setup the contentSize=CGSizeMake in the viewDidLoad of the UIViewController , i.e.,:
// Setup the Scroll View
UIScrollView *tempScrollView=(UIScrollView *)self.view;
tempScrollView.contentSize=CGSizeMake(320, 720);
// Set Stationary Background, so that while the user scroll the background is
// fixed.
UIImage *img = [UIImage imageNamed:#"bg-body.jpg"];
[tempScrollView setBackgroundColor:[UIColor colorWithPatternImage:img]];
Then, I went into the ViewController .xib file and on the UIView that is inside of the UIScrollView, I set the background color to "Clear Color".
I sure that there is a way to do this through code at the same time as setting the background of the UIScrollView, but at least that is how you can do it through IB.
Jason

transparent subview over UIimageView

as i am a new in iphone world ,i need some startup help to achieve this kind of design? background of view which has button should be transparent so that user can see product image in back.
http://www.freeimagehosting.net/uploads/cb58b72480.jpg
let me know if it requires more explanation?
thanks.
You will have to have a single UIView containing your UIImageView and UIButton.
Using InterfaceBuilder first drag the UIImageView and then drag the UIButton inside the parent UIVIew.
Or programmatically you can call the parent UIView's addSubView method first for the UIImageView and then for the UIButton view
[view addSubview:myImageView]
[view addSubview:myButton]
Either of this approach will place the instance UIButton on top of the UIImageView when the UIView is rendered
Also, FYI, transparency of a View can be controlled through its alpha property
alpha = 0 being the most transparent and
alpha = 1 being the most opaque
Hope this helps.