I am looking for away to display a static image over the tab bar? The image will not cover the entire tab bar, just part of it. But I still want to be able to use the tabs.

I am looking to do something like this. I can get the images in the tab bar, but I wan to display the image over the tab bar like image in the middle here:

enter image description here

有帮助吗?

解决方案

Allocate an UIImageView with the image and add it in the Appdelegate's Window directly over the tab bar. Make sure you disable the user interaction of the ImageView before adding it on the window.

It will be there over the tab bar without taking any action.

Update:

Get the window from appDelegate,

Appdelegate *appDelegate = ((Appdelegate*)[UIApplication sharedApplication]).delegate;
UIWindow *appDelegateWindow = appDelegate.window;

Then allocate the image view.

UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"image.png"]];
[imageView sizeToFit];

set the frames for the imageview and add it to the window.

[imageView setFrame:CGRectMake(0,380,50,50)];
[appDelegateWindow addSubView:imageView];

其他提示

You can do something like that in AppDelegate.m:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //Allocate an imageView
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"imageTabBar.png"]];

    //UITabBarController should be your rootViewController
    UITabBarController *tabBarController = (UITabBarController *) self.window.rootViewController;

    //set the imageView
    [tabBarController.tabBar addSubview:imageView];

    // Send ImageView back
    [tabBarController.tabBar sendSubviewToBack:imageView];
}

This is the result in the Simulator:

example with this code

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top