Solved

How to draw using Quartz 2D to my ViewController

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
In this article we will discuss some EI Capitan Mail app issues and provide some manual process to resolve them.
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.

749 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