Change background image on all scenes iOS 7 - ios7

The storyboard looks like the image below. In each scene I had to drag an UIImage object from the object library, size it to fit between the nav and tab bars then set its image to that baige blur with the attributes inspecter.
I'm curious, is there a way to do it in one go to all scenes from the appdelegate.m file? thanks

Try this in your AppDelegate:
[self.window setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"whatever.jpg"]]];

Related

How do I programmatically change an image in an existing UIImageView and make it fit inside the image view's constraints?

I have a UIImageView and when I set an image in that view using IB, the image is the correct size when I run the app (40x40). When I programmatically change the image using the code below, the new image is 400x400 or so. This is using the same image that I know works fine if it's set in IB. Do I have to scale the image before I add it to the UIImageView? I assumed auto-layout's constraints would automatically do this for me.
UIImage *messageTypeImage = [UIImage imageNamed:message.imageName];
[messageCell.imageView setImage:messageTypeImage];
[messageCell.contentView layoutIfNeeded];
The UIImageView's content mode is set to "Scale To Fill" and I've tried adding the code below both before and after calling setImage:
[messageCell.imageView setContentMode:UIViewContentModeScaleAspectFill];
[messageCell.imageView setClipsToBounds:YES];
Here's how the constraints are set up for the image view:
Are you using iOS 8 SDK? If so, try overriding layoutSubviews in your cell subclass and add this:
self.contentView.frame = self.bounds;
self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
There are some problems with the contentViews' of collection view/table view cells constraints/masks.
Wow. Finally found the answer here. Turns out, there's a default imageView outlet in prototype cells. I was unknowingly using that outlet and not the UIImageView I thought I was using.

Could not set tab bar image in Xcode 4.2 Programmatically

I created new tab bar project in xcode 4.2 and there is no app delegate xib file. Project has two navigation controller. I can set name of tab bar but couldn't set image. I am completely fed up with many tries. FirstViewController *firstView = [[FirstViewController alloc] initWithNibName:#"FirstViewController_iPhone" bundle:nil]
firstView.title=#"Birthdays";
firstView.tabBarItem.image=[UIImage imageNamed:#"bottomleft.png"];
SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:#"SecondViewController_iPhone" bundle:nil];
secondView.title=#"Settings";
secondView.tabBarItem.image=[UIImage imageNamed:#"bottomright.png"];
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:secondView];
navController2.navigationBarHidden=YES;
[viewControllers addObject:navController2];
Here you can see what sort of output I am getting.
Hard to tell from the code you posted, but you probably want to set the image on the tabBarItem of the UINavigationController (navController2), since it looks like that is what you directly add to you UITabBarController:
navController2.tabBarItem.image = [UIImage imageNamed:#"bottomright.png"];
The reason you can set the title is that navigation controllers by default automatically have the title of their current child view controller.
It looks like you successfully replaced the left image, however it has no transparent areas. Did you follow the guidelines for designing the tab icon?
http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/mobilehig/IconsImages/IconsImages.html
You need to use a white image on transparent background. If your background is not transparent, the whole image will just be a blue box, like the one on your left tab.
Example: To make a tab with a star on it, draw a completely white star on a transparent background. Do not use any other colors than completely white and transparent black.
You never need to do this:
[UIImage imageNamed:#"bottomleft2x.png"];
UIImage will automatically determine whether the #2x is needed or not based on the screen scale, so make it simply:
[UIImage imageNamed:#"bottomleft.png"];
Unless, of course, your resource name is actually bottomleft2x#2x.png
dude tab bar only allows white color and transparent background so if u want the picture to be like a birthday cake then draw a white birthday cake on a transparent background then add some transparent pixel in side the cake to create the looks of a cake instead of just the outline of the cake then u can set yr image to tab bar

Rotating UITabBarController Icon

I have an UITabBar in my application. One of the tab bar icons looks like a loading symbol. When the user presses the loading button I want the icon to spin/rotate until the loading is done. Should I use UIImageView to animate or something else? How should I make this happen?
Jacos, unfortunately you cannot do that with the UITabBarController and manipulate the tabBarController's tabBar properties. My best bet would be that you use a UIToolBar and assign a black color and make it appear like a tabBar and have buttons added in them as a subView so that they look like tabBarItems.
Its much more customizable, and you can even provide a scrolling experience and add more buttons to it.
I know this question is 4 years old but I had the same problem and managed to fix it by reading the tutorial in here:
https://medium.com/#werry_paxman/bring-your-uitabbar-to-life-animating-uitabbaritem-images-with-swift-and-coregraphics-d3be75eb8d4d#.bjfpbdnut
The main point is to get the view for desired UITabBarItem and the get the UIImageView from it in viewDidLoad:
UIView *plusView = self.tabBar.subviews[1];
self.plusImageView = plusView.subviews.firstObject;
self.plusImageView.contentMode = UIViewContentModeCenter;
Then in didSelectItem method you can do this:
[UIView animateWithDuration:0.4 animations:^{
[self.plusImageView setTransform:CGAffineTransformMakeRotation(M_PI/4)];
}];
My code only rotate the image view for 45 degrees but you can change as you wish.
I guess you could change the UITabBarItem's icon on a timer, but that seems pretty kludgey. You would have to pre-render each frame of your "loading" icon rather than rotate an ImageView.
Another hackey solution would be to add your ImageView to the UIWindow and move it on top of the TabBarController's TabBar (adding it to the TabBar itself is asking for trouble).
You shouldn't try to animate the actual UIImageView within the UITabBarController. I would take this approach:
Set the image for the relevant tab to nil or a blank image.
Create a UIActivityIndicatorView and add it over the tab bar. Position it over the correct tab.
[self.tabBarController.tabBar addSubview:activityIndicatorView];
When your loading task has completed, restore the normal image to the tab and remove the activityIndicator from the tab bar.

Change background image of UIImage added in UInavigation Controller

I have created a UIView, added the ImageView that UIView as a subview and the add my uiview to navigation controller. here is my code for that:-
UIView* VwTopHdr=[[UIView alloc]initWithFrame:CGRectMake(0,0.3, 1024, 122)];
header_bgimageview =[[UIImageView alloc]initWithFrame:CGRectMake(0,0.3, 1024, 122)];
header_bgimageview.image=[UIImage imageNamed:#"headerBack.png"];
[VwTopHdr addSubview:header_bgimageview];
[header_bgimageview release];
[self.navigationController.view addSubview:VwTopHdr];
Now i want to change the background image of "header_bgimageview" at rune time depending on my code conditions.here i write code to change image:-
header_bgimageview.image=[UIImage imageNamed:#"Differntimage.png"];
But i am not able to change background image using above line of code. What i have to do is removing my UIView from navigation controller create again and the added on navigation controller.
Why i am not able to change image directly instead of creating and added my view again on controller.How can i change image directly?
Expecting for your favourable reply.
Try this, which will basically invalidate the view
[VwTopHdr setNeedsDisplay];
Per class reference documentation on UIView:
setNeedsDisplay
Marks the receiver’s entire bounds rectangle as needing to be redrawn.
- (void)setNeedsDisplay

UIScrollView.size = view.size - allAdditionalBars.size (like TabBar or NavigationBar) programmatically

UIScrollView is set programmatically, please dont post answers with using .xib file.
My UIScrollView is situated in my model class, so i want the code to be able to be easly imported to another project eg. for iPad or with rotating screen.
I have a view:
self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width;, self.view.frame.size.height;)];
And my UIScrollView. I want to set it's size to cover all screen not counting all bars that my controller class will have. But i dont know how ;)
I though about subtracting self.view.frame.size.height - self.navigationController.navigationBar.frame.height and self.tabBarController.tabBar.height if each exists.
Is there any method that automatically sets UIScrollView size..?
Thank you in advance!
In your UIViewController subclass, you don't need to worry about the size of any UINavigationController or UITabBarController chrome. Those controllers will automatically resize your controller's main view to fit the appropriate content area.
If I'm creating the UIView myself in the controller's loadView, I usually just initially size it at [[UIScreen mainScreen] applicationFrame]. If I were to add a UIScrollView as a subview that would fill up the entire area of the main view (rather than just using the UIScrollView directly as the main view), I would use self.view.bounds as its frame and be sure to set autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;.