Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 故事板中选项卡栏上的自定义背景_Iphone_Ios_Storyboard_Tabbar_Ios5 - Fatal编程技术网

Iphone 故事板中选项卡栏上的自定义背景

Iphone 故事板中选项卡栏上的自定义背景,iphone,ios,storyboard,tabbar,ios5,Iphone,Ios,Storyboard,Tabbar,Ios5,所以我必须承认,直到大约一天前我添加了一个新的视图,我才发现这个代码工作得很好,所以我现在很沮丧 设置: 我有一个故事板应用程序,其中包含一个选项卡。在AppDelegate中,我有以下内容用于附加CoreData -(BOOL)应用程序:(UIApplication*)应用程序使用选项完成启动:(NSDictionary*)启动选项{ UITabBarController*tabBarController=(UITabBarController*)self.window.rootViewCon

所以我必须承认,直到大约一天前我添加了一个新的视图,我才发现这个代码工作得很好,所以我现在很沮丧

设置: 我有一个故事板应用程序,其中包含一个选项卡。在AppDelegate中,我有以下内容用于附加CoreData

-(BOOL)应用程序:(UIApplication*)应用程序使用选项完成启动:(NSDictionary*)启动选项{
UITabBarController*tabBarController=(UITabBarController*)self.window.rootViewController;
UINavigationController*navigationController=[[tabBarController-ViewController]对象索引:0];
GamesViewController*控制器=[[navigationController ViewController]对象索引:0];
controller.managedObjectContext=self.managedObjectContext;
返回YES;
}
同样在AppDelegate中,我有一个方法,可以将标准选项卡背景设置为我选择的图像:

-(void)自定义界面{
UIImage*tabBarBackground=[UIImage ImageName:@“tab_background”];
[[UITabBar外观]挫折背景图像:tabBarBackground];
}
所以这一切都很好,直到我在我的标签前面添加了另一个登录视图。我还必须更改CoreData最初设置的内容(从我的选项卡到我的登录/初始化视图)。下面是故事板外观的新设置

现在当应用程序加载时。。。背景图像最初与以前一样显示,但仅显示在第一个选项卡上。单击“关闭”后,它将再次切换为默认渐变颜色。如果返回到第一个/初始选项卡,背景不会重新应用自身,它将保持为彩色渐变

以下是修订后的ApplicationIDFinishLaunching代码:

-(BOOL)应用程序:(UIApplication*)应用程序使用选项完成启动:(NSDictionary*)启动选项{
//实例化本地上下文
NSManagedObjectContext*上下文=[self-managedObjectContext];
如果(!上下文){
//处理错误。
NSLog(@“错误:上下文为空”);
}
LoginViewController*rootViewController=[LoginViewController alloc];
rootViewController.managedObjectContext=上下文;
返回YES;
}

因此,我试图做的是,在我的选项卡加载的第一个VC中进入viewDidLoad(GameViewController),并尝试添加此项以解决问题:

-(void)viewDidLoad{
[超级视图下载];
[self.tabBarController.tabBar setBackgroundImage:[UIImage ImageName:@“dock_background”];
}
这不起作用,因此我还尝试使用AppDelegate中的原始代码,但也不起作用:

-(void)viewDidLoad{
[超级视图下载];
UIImage*tabBarBackground=[UIImage ImageName:@“tab_background”];
[[UITabBar外观]挫折背景图像:tabBarBackground];
}

所以。。。我有点卡住了。我必须做(或不做)一些如此明显的事情。。。有人有什么建议吗

非常感谢 -绘制了Delegate.h文件

@接口AppDelegate:UIResponder

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UIImageView *imgV;
@property (strong, nonatomic) UIViewController *viewController;
@property (strong, nonatomic) UITabBarController *tabBarController;

@end
Delegate.m文件

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

        self.viewController = [[DeskboardVctr alloc] initWithNibName:@"DeskboardVctr" bundle:nil];




    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.delegate=self;
    self.imgV=[[UIImageView alloc] init];
    self.imgV.frame=CGRectMake(0, 0, 1024, 49);
    [[self.tabBarController tabBar] insertSubview:self.imgV atIndex:1];
    self.tabBarController.delegate=self;
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];

    return YES;
}
Tabbar委托方法

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    NSUInteger index=[[tabBarController viewControllers] indexOfObject:viewController];
        switch (index) {
            case 0:
                self.imgV.image=[UIImage imageNamed:@"t1.png"];
                break;
            case 1:
                self.imgV.image=[UIImage imageNamed:@"t2.png"];
                break;
            case 2:
                self.imgV.image=[UIImage imageNamed:@"t3.png"];
                break;
            case 3:
                self.imgV.image=[UIImage imageNamed:@"t4.png"];
                break;
            case 4:
                self.imgV.image=[UIImage imageNamed:@"t5.png"];
                break;
            default:
                break;
        }
    return YES;
}
希望你能帮上忙
谢谢

您想定制tabbarWow吗。现在我看到了编码的深夜效应有时能做些什么。原来答案一直就在我面前。我的视图试图加载图像“dock_background.png”,而不是tab_background.png(实际文件名)。因为那个图像不存在。。。它默认为正常渐变背景色。Doh!!!谢谢你的帮助,尽管。。。我会记住你的代码,因为它看起来很有前途。