我们如何反复在工具栏中添加图像?

时间:2012-09-18 10:56:47

标签: iphone objective-c ios uitoolbar ipad

请任何人都可以在X轴上重复添加图像。 提前致谢

1 个答案:

答案 0 :(得分:0)

这里是按类别将图像添加到UIToolBar的代码....

.h文件:

#import <UIKit/UIKit.h>

@interface UIToolbar (AddtitionalFuntionality)

+(void)setToolbarBack:(NSString*)bgFilename toolbar:(UIToolbar*)toolbar;

@end

.m文件:

#import "UIToolbar+AddtitionalFuntionality.h"

@implementation UIToolbar (AddtitionalFuntionality)

+(void)setToolbarBack:(NSString*)bgFilename toolbar:(UIToolbar*)bottombar {  
    // Add Custom Toolbar
    UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:bgFilename]];
    iv.frame = CGRectMake(0, 0, bottombar.frame.size.width, bottombar.frame.size.height);
    iv.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    // Add the tab bar controller's view to the window and display.
    if([[[UIDevice currentDevice] systemVersion] intValue] >= 5)
        [bottombar insertSubview:iv atIndex:1]; // iOS5 atIndex:1
    else
        [bottombar insertSubview:iv atIndex:0]; // iOS4 atIndex:0
    bottombar.backgroundColor = [UIColor clearColor];
}

@end

调用声明将是....

[UIToolbar setToolbarBack:@"tool-bar.png" toolbar:toolBarTop]; 

类别Here

的源代码

链接到博客:Site