定制uitabbaritem

时间:2012-08-28 06:28:25

标签: objective-c ios uitabbaritem

您好我一直在尝试自定义UItabBarItem,我发现一些代码可以自定义UItabbaritem,但它们不仅仅是在为我工作。当我使用这两个代码中的任何一个时,没有任何反应。任何帮助将不胜感激。 thx提前

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

我也试过这个,但是这个也没用。

 [[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];

这是我的代码

ViewController.h

//  ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

{
    UIImage *img;
    UITabBarItem *tabBarItem;

}

@end

我的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

我的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

我还有其他ViewContoller但是现在我的焦点是一个viewController,如果我可以自定义那个我可以为其他人做的,为了节省节省空间和时间。 THX

1 个答案:

答案 0 :(得分:1)

可以使用tutorial

完成UI元素自定义