Custom background image on UIToolbar in IOS5 SDK

后端 未结 5 516
轮回少年
轮回少年 2020-12-12 22:35

Downloaded IOS5 SDK yesterday, and this code which I use to set my UIToolbar\'s background to a custom image stopped working. If I set the target to IOS4.3 and below it stil

5条回答
  •  清歌不尽
    2020-12-12 23:15

    This worked on my toolbar:

    //toolBar background image set based on iOS version
        [[UIDevice currentDevice] systemVersion];
    
        if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9) {
    
            //iOS 5
            UIImage *toolBarIMG = [UIImage imageNamed: @"toolBar_brown.png"];  
    
            if ([toolBar respondsToSelector:@selector(setBackgroundImage:forToolbarPosition:barMetrics:)]) { 
                [toolBar setBackgroundImage:toolBarIMG forToolbarPosition:0 barMetrics:0]; 
            }
    
        } else {
    
            //iOS 4
            [toolBar insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"toolBar_brown.png"]] autorelease] atIndex:0]; 
    
        }
    

提交回复
热议问题