gpt4 book ai didi

objective-c - 自定义 uitabbaritem

转载 作者:行者123 更新时间:2023-11-29 04:27:18 24 4
gpt4 key购买 nike

您好,我一直在尝试自定义 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 ,如果我可以自定义一个,那么我也可以为其他人做同样的事情,以节省空间和时间。谢谢

最佳答案

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

关于objective-c - 自定义 uitabbaritem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12153838/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com