[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to draw using Quartz 2D to my ViewController

Posted on 2015-02-09
1
Medium Priority
?
246 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

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…
Set up iPhone and iPad email signatures to always send in high-quality HTML with this step-by step guide.
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

650 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