首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自定义uitabbaritem

自定义uitabbaritem
EN

Stack Overflow用户
提问于 2012-08-28 14:28:25
回答 1查看 687关注 0票数 0

你好,我一直在尝试定制UItabBarItem,我找到了一些可以定制UItabbaritem的代码,但它们不只是我在工作。当我使用这两个代码中的任何一个时,什么都不会发生。任何帮助都将不胜感激。提前进行thx

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

我也试过这个,但这个也不起作用。

代码语言:javascript
复制
 [[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

代码语言:javascript
复制
//  ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

{
    UIImage *img;
    UITabBarItem *tabBarItem;

}

@end

我的ViewController.m

代码语言:javascript
复制
//  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

代码语言:javascript
复制
//  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

代码语言:javascript
复制
//  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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-28 14:50:10

可以使用tutorial完成UI元素的自定义

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12153838

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档