Solved

How to draw using Quartz 2D to my ViewController

Posted on 2015-02-09
1
167 Views
Last Modified: 2015-02-09
This is sort of a beginner-level question.  I have inherited an iOS project and it is implemented with a few ViewControllers with associated XIB files.  The XIB files contain various widgets that are controlled by code in the ViewControllers (which I think is the standard way of doing this).

However, I need to do some custom drawing (rectangles, lines, circles, text) in between the widgets, and I'd like to use the Quartz 2D library to do this.  I've never used Quartz2D, and most of the sample code I find is centered around the View, not the ViewController.

Most  of it has to do with implementing the "drawRect" method of your View.  However, my ViewController does not have a "drawRect" function, as far as I can tell.  Is there a way I can implement a "drawRect" function on my ViewController or whatever View it is controlling?

*** addendum: I have researched a bit further and reminded myself that the operational UIView is a property of the UIViewController, and it seems like UIView is created automatically by the application and bundled together with my XIB and ViewController (I think we selected "also create XIB" when we were creating a ViewController, so the UIView is implied?). I don't see where this default UIView instantiation occurs. But I assume the way to draw to it is to subclass it?

If so, what is the *cleanest* way to subclass this UIView and get access to drawRect while maintaining the connection to the existing ViewController and XIB (or storyboard)? I inherited the project and this change needs to be low-impact.

Thanks for any help/thoughts.
0
Comment
Question by:RonMexico
1 Comment
 

Accepted Solution

by:
RonMexico earned 0 total points
ID: 40599294
Was provided the answer: make a subclass of UIView and override -drawRect: to do your custom drawing. In the xib, select the view of your view controller, go to the Identity Inspector (third tab in the right sidebar in Xcode), and replace UIView with your custom subclass.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

What's a UDID? If you're involved in developing, testing, or even reviewing an iOS application that's in beta, then at some point you may need to know the UDID for any iOS devices that you'll be testing on. What's the UDID? It stands for Unique Dev…
When Apple released Swift last year, the aim was to introduce a new programming language for Cocoa and Cocoa Touch that was fast, easy and effective, like the name connotes. Apple succeeded. Swift is designed to couple with Objective-C program…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now