JASidePanel iOS:导航栏上的样式左键

时间:2013-04-20 18:35:53

标签: ios uinavigationbar uibarbuttonitem

所以我一直试图在导航栏上设置左侧栏按钮的样式。 主要是按钮样式我不想取样(与UIButton样式设置为自定义相同的样式)。

有谁知道怎么做? 谢谢, 詹姆斯

1 个答案:

答案 0 :(得分:14)

在JASidePanelController.m中查看此函数

+ (UIImage *)defaultImage {
    static UIImage *defaultImage = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        UIGraphicsBeginImageContextWithOptions(CGSizeMake(20.f, 13.f), NO, 0.0f);

        [[UIColor blackColor] setFill];
        [[UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 20, 1)] fill];
        [[UIBezierPath bezierPathWithRect:CGRectMake(0, 5, 20, 1)] fill];
        [[UIBezierPath bezierPathWithRect:CGRectMake(0, 10, 20, 1)] fill];

        [[UIColor whiteColor] setFill];
        [[UIBezierPath bezierPathWithRect:CGRectMake(0, 1, 20, 2)] fill];
        [[UIBezierPath bezierPathWithRect:CGRectMake(0, 6,  20, 2)] fill];
        [[UIBezierPath bezierPathWithRect:CGRectMake(0, 11, 20, 2)] fill];   

        defaultImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

    });
    return defaultImage;
}

这是在customButton上创建3行的部分。

这被称为:

- (UIBarButtonItem *)leftButtonForCenterPanel {
    return [[UIBarButtonItem alloc] initWithImage:[[self class] defaultImage] style:UIBarButtonItemStylePlain target:self action:@selector(toggleLeftPanel:)];
}

因此,将其定制为例如:

- (UIBarButtonItem *)leftButtonForCenterPanel {
UIImage *faceImage = [UIImage imageNamed:@"facebook.png"];
UIButton *face = [UIButton buttonWithType:UIButtonTypeCustom];
face.bounds = CGRectMake( 0, 0, faceImage.size.width, faceImage.size.height );
[face setImage:faceImage forState:UIControlStateNormal];
[face addTarget:self 
             action:@selector(toggleLeftPanel:) 
   forControlEvents:UIControlEventTouchUpInside];
return [[UIBarButtonItem alloc] initWithCustomView:face];
}

请根据您的具体情况进行更改。希望这会有所帮助...