项目作者: mindbody

项目描述 :
Embed iOS app settings and shortcuts inside a hidden panel
高级语言: Objective-C
项目地址: git://github.com/mindbody/MBDebugPanel.git
创建时间: 2014-02-07T00:41:51Z
项目社区:https://github.com/mindbody/MBDebugPanel

开源协议:MIT License

下载


MBDebugPanel

Version
Platform

MBDebugPanel is a development helper to let you easily add ‘behind the scenes’ shortcuts to your app. It is intended for use during development & debugging.

It offers a simple way to define helper tools, and present them in a Table View above the root window:

Basic Usage

  1. // Define a component.
  2. MBDebugPanelSimpleButtonComponent *buttonComponent
  3. = [[MBDebugPanelSimpleButtonComponent alloc] initWithTitle:@"Trigger Some Call"
  4. buttonTitle:@"Do it!"
  5. onButtonPressed:^{
  6. /*
  7. --- Your code goes here ---
  8. You can skip to a ViewController, trigger some API request,
  9. run some NSLog's ... anything you'd like to trigger.
  10. */
  11. // (Optionally) dismiss the panel immediately and return to your app.
  12. [MBDebugPanel hide];
  13. }];
  14. [MBDebugPanel addComponent:buttonComponent];
  15. ...
  16. // Present the panel above the root view.
  17. [MBDebugPanel show];

Included Components

MBDebugPanel ships with two MBDebugPanelComponent implementations to handle common scenarios:



MBDebugPanelSimpleSwitchComponent — renders a UISwitch and description label

Imgur



MBDebugPanelSimpleButtonComponent — renders a UIButton and description label

Imgur

Make your own components

You can easily define your own components by implementing the MBDebugPanelComponent protocol.

“Components” are objects that represent a row in the Debug Panel. Components need only conform to the MBDebugPanelComponent protocol and implement two methods:

  1. @protocol MBDebugPanelComponent <NSObject>
  2. @required
  3. // The height this component will require in a UITableView when
  4. // represented as a UITableViewCell
  5. -(CGFloat)cellHeight;
  6. // A UITableView cell representing the component.
  7. // `indexPath` is passed so you can reuse cells with -[UITableView dequeueReusableCellWithIdentifier:forIndexPath]
  8. -(UITableViewCell*)cellForDisplayInTableView:(UITableView*)tableView atIndexPath:(NSIndexPath*)indexPath;

Removing components

Components can easily be removed from the DebugPanel. This is particularly useful if you want certain components only visible in certain contexts of your app.

For instance, if your app has a “Create Account” screen, you might wish to quickly fill in some text fields with fake information.

However, you only want this component visible when your app is on that screen:

  1. @implementation MySignUpViewController
  2. MBDebugPanelSimpleButtonComponent *makeFakeUserButton_;
  3. -(void)viewWillAppear:(BOOL)animated
  4. {
  5. makeFakeUserButton_ = [[MBDebugPanelSimpleButtonComponent alloc] initWithTitle:@"Make Fake User" buttonTitle:@"Create" onButtonPressed:^{
  6. self.firstName.text = @"Fake";
  7. self.lastName.text = @"User";
  8. self.email.text = @"fake.email@example.com"
  9. ...
  10. ...
  11. [MBDebugPanel hide];
  12. }];
  13. [MBDebugPanel addComponent:makeFakeUserButton_];
  14. }
  15. -(void)viewWillDisappear:(BOOL)animated
  16. {
  17. [MBDebugPanel removeComponent:makeFakeUserButton_];
  18. }
  19. ...

@end

Additional APIs

A detailed description of all available APIs is visible in MBDebugPanel.h

Demo App

To run the example project; clone the repo and open MBDebugPanel.xcworkspace. Select and run the Demo app’s scheme.

Installation

MBDebugPanel is available through CocoaPods, to install it simply add the following line to your Podfile:

  1. pod "MBDebugPanel"

Authors

Matthew Holden, matthew.holden@mindbodyonline.com

License

MBDebugPanel is available under the MIT license. See the LICENSE file for more info.