MBDebugPanel 0.2.1

MBDebugPanel 0.2.1

测试已测试
Lang语言 Obj-CObjective C
许可 MIT
发布上次发布2014年12月

Matthew HoldenMatthew Holden 维护。



  • 作者
  • Matthew Holden

MBDebugPanel 是一个开发辅助工具,让您轻松地为您的应用程序添加“幕后”快捷方式。它旨在用于开发与调试。

它以 简单的方式 定义辅助工具,并在根窗口上方以表格视图的形式展示它们。

基本用法

// Define a component.
MBDebugPanelSimpleButtonComponent *buttonComponent
= [[MBDebugPanelSimpleButtonComponent alloc] initWithTitle:@"Trigger Some Call"
                                               buttonTitle:@"Do it!"
                                           onButtonPressed:^{
    /* 
      --- Your code goes here ---
      You can skip to a ViewController, trigger some API request,
       run some NSLog's ... anything you'd like to trigger.
    */

    // (Optionally) dismiss the panel immediately and return to your app.
    [MBDebugPanel hide];
}];

[MBDebugPanel addComponent:buttonComponent];

...

// Present the panel above the root view.
[MBDebugPanel show];

包含的组件

MBDebugPanel 包含两个 MBDebugPanelComponent 实现,用于处理常见场景。


MBDebugPanelSimpleSwitchComponent -- 渲染 UISwitch 和描述标签

Imgur


MBDebugPanelSimpleButtonComponent -- 渲染 UIButton 和描述标签

Imgur

创建自己的组件

您可以通过实现 MBDebugPanelComponent 协议轻松定义自己的组件。

“组件”是代表调试面板中某一行对象的对象。组件只需遵循 MBDebugPanelComponent 协议并实现两个方法即可。

@protocol MBDebugPanelComponent <NSObject>
@required

// The height this component will require in a UITableView when
// represented as a UITableViewCell
-(CGFloat)cellHeight;

// A UITableView cell representing the component.
// `indexPath` is passed so you can reuse cells with -[UITableView dequeueReusableCellWithIdentifier:forIndexPath]
-(UITableViewCell*)cellForDisplayInTableView:(UITableView*)tableView atIndexPath:(NSIndexPath*)indexPath;

移除组件

可以轻松地从 DebugPanel 中移除组件。这特别有用,如果您只想在某些应用程序的特定上下文中显示某些组件。

例如,如果您的应用程序有一个“创建账户”屏幕,您可能希望快速将一些文本字段填写为假信息。

但是,您只想在该屏幕上显示此组件

@implementation MySignUpViewController

MBDebugPanelSimpleButtonComponent *makeFakeUserButton_;

-(void)viewWillAppear:(BOOL)animated
{
    makeFakeUserButton_ = [[MBDebugPanelSimpleButtonComponent alloc] initWithTitle:@"Make Fake User" buttonTitle:@"Create" onButtonPressed:^{
        self.firstName.text = @"Fake";
        self.lastName.text  = @"User";
        self.email.text = @"[email protected]"
        ...
        ...

        [MBDebugPanel hide];
    }];
    [MBDebugPanel addComponent:makeFakeUserButton_];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [MBDebugPanel removeComponent:makeFakeUserButton_];
}

...

@end

附加 API

所有可用 API 的详细描述可在 MBDebugPanel.h 中找到。

示例应用程序

要运行示例项目;克隆仓库并打开 MBDebugPanel.xcworkspace。选择并运行示例应用程序的方案。

安装

作者

Matthew Holden, [email protected]

许可

MBDebugPanel 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。