SimpleDrawing for iOS


Introduction

As the name implies, SimpleDrawing is a simple open source drawing app for iOS. I created SimpleDrawing to serve as an example of how to handle the basic drawing features on an iOS device, including:

  • Tools such as pen, line, text, rectangle, ellipse, and eraser
  • Individual tool settings such as primary and secondary color, line width, transparency, and font size
  • Importing photos from the photo album
  • Multi-level undo and redo operations
  • Layers with individual levels of transparency
  • Sharing via mail, Twitter, camera roll and more

The drawing functionality of SimpleDrawing can be used within your own applications with minimal effort. The design of the code also makes it easy to add your own tools by inheriting from SDDrawingTool and overriding (usually) only one method.

Installation

It is possible to use the drawing functionality of SimpleDrawing within your own project. First add the contents of the SimpleDrawing project directly to your Xcode project by drag-and-drop. Next, add the required frameworks: Quartz, Twitter, and MessageUI. Select the main.m file from SimpleDrawing and uncheck it’s “Target Membership” for your target in the File inspector. Finally, disable ARC using the -fno-objc-arc flag for the files BGRSLoupeLayer.m, BSBrightnessSlider.m, and RSColorPickerView.m.

Usage

Once the required files are included in your project, with just a few lines of code you can display a view that lets you browse and create new drawings:

//instantiate the view controller
NSBundle *bundle = [NSBundle bundleForClass:[SDDrawingsViewController class]];
UIStoryboard *storyboard;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    storyboard = [UIStoryboard storyboardWithName:@"SDSimpleDrawing_iPad" bundle:bundle];
} else {
    storyboard = [UIStoryboard storyboardWithName:@"SDSimpleDrawing_iPhone" bundle:bundle];
}
SDDrawingsViewController *viewController = [storyboard instantiateInitialViewController];

//present the view controller
[self presentViewController:viewController animated:YES completion:nil];

Using the SDSimpleDrawing_iPad storyboard presents the user with a suitable iPad UI:

You can download the source code for SimpleDrawing at my repository here.

UPDATE: The SimpleDrawing app is now available for free from the Apple App Store if you want a free and easy way to try the app.

Advertisements

5 thoughts on “SimpleDrawing for iOS

  1. Pingback: SimpleDrawing Available Free on the App Store « Development Technobabble

    1. nwoolls Post author

      I haven’t though that’s a very interesting idea. If the shape were in its own layer that shouldn’t be too difficult to do.

      Reply
  2. ighulammustafa

    How would you go about implementing a zooming behavior. For example, what if the drawing canvas is larger than the actual device screen size i.e. 2048 x 2048 canvas. I tried to implement a solution, using UIView transform property, but i’m getting very poor performance — specially on the iPhone.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s