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

标签 ios uinavigationbar uibarbuttonitem

因此我一直在尝试在导航栏上设置左栏按钮的样式。
主要是我不想取消样式设置的按钮样式(与设置为custom的UIButton样式相同的样式)。

有人知道吗?
谢谢,
詹姆士

最佳答案

在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];
}

请根据您的情况进行更改。希望这可以帮助...

关于ios - JASidePanel iOS:导航栏上的样式左键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16123823/

相关文章:

ios - 在 UITableView 上执行具有多个状态的 segue

ios - 如何启动单个计时器并从多个 View 访问它?

ios - Swift 上基于流的 JSON 解析

ios - 如何删除 iOS 13 中带有外观的导航栏背景?

uibutton - 当用作左侧或右侧导航栏项目时,具有自定义 View 的 UIBarButtonItem 在 iOS 7 上未正确对齐

ios - 根据 View 是否为空显示/隐藏 UIBarButtonItem

swiftui - UIKit > SwiftUI > UIKit 时未显示导航栏项目

ios - 有没有办法判断 iOS 应用程序是否意外关闭?(崩溃,强制关闭)

ios - UIBarButtonItem 的单击事件似乎在 MonoTouch 中不起作用

ios - UINavigationBar 中的滑动手势