Could not set tab bar image in Xcode 4.2 Programmatically - objective-c

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

Related

How to use NSTitlebarAccessoryViewController?

Can anyone tell me how to use NSTitlebarAccessoryViewController, to add subview to a view with an example? As I am new to mac programming you may have to explain from basics. Please.
NSTitlebarAccessoryViewController is for adding subviews to the windows title bar.
Here is a example:
Set up a view in interface builder. Go to the `applicationDidFinishLaunching: method to add the view to the title bar.
The code would be the following:
NSTitlebarAccessoryViewController* vc = [[NSTitlebarAccessoryViewController alloc] init];
vc.view = self.view;
vc.layoutAttribute = NSLayoutAttributeRight;
[self.window addTitlebarAccessoryViewController:vc];
You can play with the size of the view to make it fit into the title bar.
Update
OS X 10.11 introduced the new layoutAttribute left.
There are now three layoutAttributes in total. bottom adds a bar beneath the titleBar (like the tabBar) and left/right places your subview within the titleBar.

set both backIndicatorImage and backIndicatorTransitionMaskImage on backbarbutton in IOS7 didnot show particular image

I searched all the topics about backbarbutton custom, but seems failed to find answers about my problem on backbarbutton.
To keep the property called interactivePopGestureRecognizer of UINavigationController, using leftBarButton to replace backBarButton is not a valid solution. But I want to custom the backbarbutton with a image, so I use the following code in my controller ViewDidLoad:
UIBarButtonItem * btnBack = [[UIBarButtonItem alloc]init];
btnBack.title = #"";
self.navigationController.navigationBar.backIndicatorImage = [UIImage imageNamed:#"backBtn"];
self.navigationController.navigationBar.backIndicatorTransitionMaskImage = [UIImage imageNamed:#"backBtn"];
self.navigationItem.backBarButtonItem = btnBack;
when I run my project, it shows just a blue rectangle in the place where backBarButton always show.
But the original image just like the system barbutton that called reply.
However, it has a different effect, just change to the image named "Drinks" which is a black image that show a glass of juice.
after run my project the place where always show backBarButton show a blue image just like "Drinks".
what happend! How can I custom my backBarButton with the giving image named backBtn.png, is there anyone can help me? Thanks in advance! For image submit has been reject, I discrible my problem in words.
The Image has be transparent where there should be nothing to be drawn. It should be opaque where the content of the image will be drawn. At least that worked for me. The final color will be tinted by the navigationbar's tintColor anyway.

SKStoreProductViewController title color

How do you change the title color and/or bar tint color in a SKStoreProductViewController?
I'm using the appearance API to set navigation bars to a dark color and the text to white. It changes the title color but not the bar tint color in my SKStoreProductViewController.
I don't think you can. At least not on iOS 7. On iOS 6 you can use the UIAppearance protocol and the SKSPVC will pick up the appearance you set on the UINavigationBar.
As noted on this thread, the SKSPVC is a remote view controller so it's inaccesible programmatically, meaning that you can't set it's appearance directly (or indirectly?).
Do the following to avoid the SKStoreProductViewController to take over a tintColor of value WHITE:
#define kCOLOR_NON_WHITE_COLOR [UIColor darkGrayColor]
// CHANGE ALL TINTING BEFORE WE CREATE An INSTANCE OF THIS BROKEN PIECE
[UIWindow appearance].tintColor = kCOLOR_NON_WHITE_COLOR;
[UIView appearance].tintColor = kCOLOR_NON_WHITE_COLOR;
[UINavigationBar appearance].tintColor = kCOLOR_NON_WHITE_COLOR;
[UIBarButtonItem appearance].tintColor = kCOLOR_NON_WHITE_COLOR;
// NOW CREATE THE THING
SKStoreProductViewController *controller = [[[SKStoreProductViewController alloc] init] autorelease];
This draws all the UIBarButtonItems and the UISegmentedControls in this controller in the defined color AFAIK and thus makes the controller more like your apps design.
IMPORTANT: Just do not forget(!!!) to change all the tinting back after you dismissed this controller, otherwise fresh created views in your app might take over the enforced tinting.
UPDATE: As you might already have found out the following to manipulate the appearance does not work:
[UINavigationBar appearanceWhenContainedIn:[SKStoreProductViewController class], nil]
This fix is for iOS 7 & 8 on iOS 6 you have different issues. =)

UIActivityViewController color

It seems like there is no Apple permitted way to change the color of a uiactivityviewcontroller. I am creating it in my iPad app like this:
UIActivityViewController *activity = [[UIActivityViewController alloc] initWithActivityItems:#[#"test"] applicationActivities:nil];
shareOptions = [[UIPopoverController alloc] initWithContentViewController:activity];
[shareOptions presentPopoverFromBarButtonItem:actionBarButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
This currently presents the popover with a blueish background color. I have seen a black background color used so I know it is possible. Another developer mentioned to me he thought on the iPhone at least it appears to be determined by the status bar color (as setting the status bar color to black opaque in the info.plist made the activityview black). This did not seem to have an effect on the iPad version. Does anyone have any ideas/suggestions?
Thanks!
UPDATE:
Setting activity.view.backgroundColor yields a weird result where most of the view is the set color but the edges are still the original blue
That's mentioned on the WWDC 2012 Video : Session 200 - What's new in Cocoa Touch.
The blueish part is a default layover you can deactivate with
UIPopoverBackgroundView +(BOOL)wantsDefaultContentAppearance

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.