简体   繁体   中英

customizing the uitabbaritem

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

用户界面元素的自定义可以使用本教程完成

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM