[英]customizing the uitabbaritem
您好,我一直在嘗試自定義UItabBarItem,但我發現一些代碼可以自定義UItabbaritem,但它們不僅對我有用。 當我使用兩個代碼中的任何一個時,什么都沒有發生。 任何幫助將不勝感激。 提前
[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,如果我可以自定義一個,那么我可以為其他人做,以節省空間和時間。 謝謝
用戶界面元素的自定義可以使用本教程完成
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.