Can I give a UIToolBar a custom background in my iPhone app?

后端 未结 10 960
误落风尘
误落风尘 2020-12-02 09:00

Is it possible to give a UIToolBar a custom background from an image rather than the usual tinted blue/black fade out?

I\'ve tried giving the view a background and s

10条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 09:32

    To be iOS 5 compliant you can do something like this

    -(void) addCustomToolbar {
    
        // Add Custom Toolbar
        UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"customToolbar.png"]];
        img.frame = CGRectMake(-2, -20, img.frame.size.width+4, img.frame.size.height);
    
        // Add the tab bar controller's view to the window and display.
    
        if( SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO( @"5.0" ) )
           [self.tabBarController.tabBar insertSubview:img atIndex:1]; // iOS5 atIndex:1
        else
          [self.tabBarController.tabBar insertSubview:img atIndex:0]; // iOS4 atIndex:0
    
        self.tabBarController.tabBar.backgroundColor = [UIColor clearColor];
    
        // Override point for customization after application launch.
        [self.window addSubview:tabBarController.view];
    
    }
    

提交回复
热议问题