Custom colored UITabBar icons - ios4

Im trying to implement custom colors in UITabBar.But i dont know what the problem is.I placed an image on 1 tabBar.when the tabBar is active,i want one image and when tabBar is inactive,i want another image to be displayed on the same tabBar.How?
Also guide me that the image is placed at the center of the tabBar.Please tell me the Xcode for this implementation-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
for(UIView *view in self.tabBarController.tabBar.subviews) {
if([view isKindOfClass:[UIImageView class]]) {
[view removeFromSuperview];
}
}
[self.tabBarController.tabBar insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Icon-a.png"]] autorelease] atIndex:0];
}
(void)viewWillDisappear:(BOOL)animated {
//[superviewWillDisappear:animated];
for(UIView *view in self.tabBarController.tabBar.subviews) {
if([view isKindOfClass:[UIImageView class]]) {
[view removeFromSuperview];
}
}
[self.tabBarController.tabBar insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Icon-c.png"]] autorelease] atIndex:0];
}
I used these methods to implement my task.But i coudn't get the solution.Please help me

You may refer the source code available in the following link, Hope it will fix your problem..
https://github.com/rumex/RXCustomTabBar

Related

Game center issue

Im New In Development think and i'm wondering about some things like the game center button , how to connect that button is there any ready code for that, the same question about the rate button . Can any one tell me how to do that
//Rate Button
if ([node.name isEqualToString:#"rateButton"]) //Your Rate Button name
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"itms-apps://itunes.apple.com/app/id919770861"]];//itms-apps://itunes.apple.com/app/idYourAppID
}
//Game Center Button
- (void)showGKGameCenterViewController:
(UIViewController *)viewController
{
if (!_enableGameCenter) {
NSLog(#"Local play is not authenticated");
}
GKGameCenterViewController *gameCenterViewController =
[[GKGameCenterViewController alloc] init];
gameCenterViewController.gameCenterDelegate = self;
gameCenterViewController.viewState =
GKGameCenterViewControllerStateAchievements;
[viewController presentViewController:gameCenterViewController
animated:YES
completion:nil];
}
if ([node.name isEqualToString:#"GameCenter"]) //Your Game Center Button Name
{
[self showGKGameCenterViewController:yourViewController];
}

Textfield in cocos2d/kobold2d not showing color

I need to create a textfield where a player in my game can enter their name for highscore purposes. I followed this question: UITextField Example in Cocos2d , and successfuly created a textfield with the keyboard. However, the textfield's text is white and the background color is also white so I cannot see the textfield, only the keyboard.
Here is the code:
appdelegate.h
#import "KKAppDelegate.h"
#interface AppDelegate : KKAppDelegate
{
UITextField *nameTextField;
}
-(void)specifyPlayerName;
#end
appdelegate.m
#implementation AppDelegate
-(void) initializationComplete
{
#ifdef KK_ARC_ENABLED
CCLOG(#"ARC is enabled");
#else
CCLOG(#"ARC is either not available or not enabled");
#endif
}
- (void)specifyPlayerName
{
NSLog(#"called");
nameTextField = [[UITextField alloc] initWithFrame:CGRectMake(60, 165, 200, 90)];
[nameTextField setDelegate:self];
[nameTextField setText:#""];
[nameTextField setTextColor: [UIColor colorWithRed:0 green:0 blue:0 alpha:1.0]];
[[[[CCDirector sharedDirector] openGLView] window] addSubview:nameTextField];
[nameTextField becomeFirstResponder];
}
- (BOOL)textFieldShouldReturn:(UITextField*)textField {
//Terminate editing
[textField resignFirstResponder];
return YES;
}
- (void)textFieldDidEndEditing:(UITextField*)textField {
if (textField==nameTextField) {
[nameTextField endEditing:YES];
// here is where you should do something with the data they entered
GameData* data = [GameData sharedData];
data.playerName = nameTextField.text;
NSLog(#"entered: %#", data.playerName);
}
}
The method is being called from another class/button
[[[UIApplication sharedApplication] delegate]performSelector:#selector(specifyPlayerName)];
I tried to set the color of the textfield, but it is still showing up as all white. Any help would be appreciated.
I found out that the textfield was hidden behind the other view, so
[[[CCDirector sharedDirector] openGLView] addSubview:nameTextField];
instead of
[[[[CCDirector sharedDirector] openGLView] window] addSubview:nameTextField];
The textfield colors are default to be black on white.

Rotation issue using UIActivityViewController in a MapView

In my iOS app I have a Map View that I called mappa.
I just add a UIActivityViewController that appears when a callout is pressed from an annotation View.
I use this code to display it:
- (void)mapView:(MKMapView *)mapView
annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control {
[mappa deselectAnnotation:view.annotation animated:YES];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0) {
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[self, [NSURL URLWithString:#"http://www.AppStore.com/iToretto"]]
applicationActivities:nil];
activityViewController.excludedActivityTypes = #[UIActivityTypePostToWeibo, UIActivityTypeAssignToContact, UIActivityTypeCopyToPasteboard ];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
self.annotationPopoverController = pop;
//show the popover next to the annotation view (pin)
[pop presentPopoverFromRect:view.bounds
inView:view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
self.annotationPopoverController.delegate = self;
}
}
}
My problem is that when I rotate this popover, I have a frame Issue (like this). I understand that the solution is to override :
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration;
But when I try to display popover in landscape mode in this way I have multiple errors:
if (UIInterfaceOrientationLandscapeLeft && [self.annotationPopoverController isPopoverVisible]) {
[self.annotationPopoverController presentPopoverFromRect:view.bounds
inView:view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
Because "view.bounds" and "view" is a local declaration of MKAnnotation
So, How can I fix it?! Does anyone have a solution?! Thanks in advance.

uitabbarcontroller / uitabbar in navigation based project

I have created navigation based project. and in second screen i want to add uitabbarcontroller. so can any one suggest how i do this.
i already did lot of search but no success yet. so please can you provide a simple sample of this. i already tried below discussion but i think its not a good approach.
Navigation Based Application with TabBar
Thanks
Actually this is the correct approach. The one thing that is not correct is where the controllers are allocated. This is happened in the previous controller, the one that is making the push, but should be allocated in the object that is responsible, the TabBarController.
When you implement your action to show the UITabBarController make the following code:
- (void) theAction {
SomeTabBarControllerSubClass *controller = [[SomeTabBarControllerSubClass alloc] init];
[self.navigationController pushViewController:controller animated:YES];
[controller release];
}
Then when you implement the SomeTabBarControllerSubClass class:
(.h)
#interface SomeTabBarControllerSubClass : UITabBarController {
UIViewController *first;
UIViewController *second;
}
#end
(.m)
#implementation SomeTabBarControllerSubClass
- (void) viewDidLoad {
first = [[UIViewController alloc] init]; //Or initWithNib:
second = [[UIViewController alloc] init];
first.view.backgroundColor = [UIColor greenColor] //Just example
second.view.backgroundColor = [UIColor redColor] //Just example
first.tabBarItem.image = [UIImage imageNamed:#"someImage.png"];
self.viewControllers = [NSArray arrayWithObjects:first,second,nil];
}
- (void) dealloc {
[first dealloc];
[second dealloc];
[super dealloc];
}
#end

TO customize the color of UITabBar in Xcode

Hi Could you please let me know how to change the default colour of a tababar in Xcode i hav already tried this :
(void)viewDidLoad {
[super viewDidLoad];
UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"UITabBar.png"]];
img.frame = CGRectOffset(img.frame, 0, 1);
[tabBar1 insertSubview:img atIndex:0];
[img release];
but it doesnt work for me so can you please tel me in detail how can i change the colo
I know, this is an old thread, but nonetheless for all of you looking for an answer.
One of the ways to customize the look of UITabBar is to override drawRect: method with use of categories. Choose to create new file in your Xcode project, choose Objective-C category, then type UITabBar for Category On textfield. Next, declare drawRect: method in your category .h file and implement it in category .m file like this:
- (void)drawRect:(CGRect)rect {
UIImage *img = [UIImage imageNamed: #"tabbarBackground"];
[img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
This will change the looks of all UITabBar instances in your app.
Hope this helps.

Resources