0

Hello I have been trying to customize the UItabBarItem and i have found some piece of code can customize the UItabbaritem but they aren't just working me. Nothing happens when i use any of the two code. Any help will be appreciated. thx in advance

[yourTabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor, 
[NSValue valueWithUIOffset:UIOffsetMake(0,0)], UITextAttributeTextShadowOffset, 
[UIFont fontWithName:@"Helvetica" size:18.0], UITextAttributeFont, nil]
forState:UIControlStateNormal];

I have tried this one too, but this one isn't working either.

 [[UITabBarItem appearance] setTitleTextAttributes:
         [NSDictionary dictionaryWithObjectsAndKeys:
          [UIColor blackColor], UITextAttributeTextColor, 
          [UIColor whiteColor], UITextAttributeTextShadowColor, 
          [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, 
          [UIFont fontWithName:@"Rok" size:0.0], UITextAttributeFont, 
          nil] 
                                              forState:UIControlStateNormal];

Here is my code

ViewController.h

//  ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

{
    UIImage *img;
    UITabBarItem *tabBarItem;

}

@end

My ViewController.m

//  ViewController.m


#import "ViewController.h"

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor purpleColor]];
    img=[UIImage imageNamed:@"image2.jpg"];
    //[[UITabBarItem appearance] setTintColor:[UIColor yellowColor]];
   // [tabBarItem setTitleTextAttributes:<#(NSDictionary *)#> forState:<#(UIControlState)#>
 //   tabBarItem=[[UITabBarItem alloc]initWithTitle:@"View1" image:img tag:0];

    [[UITabBarItem appearance] setTitleTextAttributes:
     [NSDictionary dictionaryWithObjectsAndKeys:
      [UIColor blackColor], UITextAttributeTextColor, 
      [UIColor whiteColor], UITextAttributeTextShadowColor, 
      [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, 
      [UIFont fontWithName:@"Rok" size:0.0], UITextAttributeFont, 
      nil] 
                                             forState:UIControlStateNormal];
    self.tabBarItem=tabBarItem;
}

@end

And my AppDelegate.h

//  AppDelegate.h

#import <UIKit/UIKit.h>
#import "ViewController.h"
#import "ViewController1.h"
#import "ViewController2.h"

@interface AppDelegate : UIResponder <UIApplicationDelegate>

{
    UITabBarController *tabBarController;
}
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *vc;
@property (strong, nonatomic) ViewController1 *vc1;
@property (strong, nonatomic) ViewController2 *vc2;

@end

AppDelegate.m

//  AppDelegate.m

#import "AppDelegate.h"

@implementation AppDelegate

@synthesize window = _window,vc,vc1,vc2;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    tabBarController=[[UITabBarController  alloc]init];
    vc=[[ViewController alloc]init];
    vc1=[[ViewController1 alloc]init];
    vc2=[[ViewController2 alloc]init];
//    CGRect frame = CGRectMake(0.0, 0.0, 32, 48);
//    UIView *v=[[UIView alloc]initWithFrame:frame];
//    v.backgroundColor=[UIColor redColor];
   // tabBarController.view.backgroundColor=[UIColor redColor];
 //   [tabBarController adds
    NSArray *controllersArray=[[NSArray alloc]initWithObjects:vc,vc1,vc2, nil];
    // Override point for customization after application launch.
    tabBarController.viewControllers=controllersArray;
    tabBarController.selectedViewController=vc;
    [self.window setRootViewController:tabBarController];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}
@end

I have other ViewContoller also but for now my focus is one viewController , if i can customize the one then same i can do for others, for sake of saving save space and time. thx

Himanshu A Jadav
  • 2,286
  • 22
  • 34
Azerue
  • 258
  • 6
  • 16
  • 1
    You are code-dumping. Nobody is going to read this. 1) Reduce the code you post to the relevant bits. 2) Tell us what exactly is not working. – Mundi Aug 28 '12 at 06:32
  • Also not that code you post here is -by the terms of the site- licensed under a [creative commons](http://creativecommons.org/licenses/by-sa/3.0/) license, so no need to add a copyright header to the code samples. – Marijn Aug 28 '12 at 06:51

1 Answers1

1

UI element customization can be done using the tutorial

Vimal Venugopalan
  • 4,091
  • 3
  • 16
  • 25