Solved

How to draw using Quartz 2D to my ViewController

Posted on 2015-02-09
1
173 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There is a security feature on iOS devices that is nearly impenetrable when it has been activated.  This article will provide some possible solutions as well as necessary steps to take to ensure you do not end up with a locked device.
In this article we will discuss some EI Capitan Mail app issues and provide some manual process to resolve them.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

911 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

22 Experts available now in Live!

Get 1:1 Help Now