Search code examples
iosuiviewcore-graphicsboundscgrect

Get dimensions of UIView Class for CGRects?


I am currently working on an app that draws a series of rectangles (CGRect) on a view and sizes them based on the size of the UIView. This code is contain in a class file that inherits UIView (rectangle.h/rectangle.m). I cannot for some reason use self.view.bounds.height or self.view.bounds.width to get the values I need. I am using the overridden method "drawrect" that is built into the class. How can I get the view size? or if thats not possible, how can I implement this?


Solution

  • Use

    self.view.bounds.size.width 
    self.view.bounds.size.height
    

    or

    if self class is itself a UIView

    self.bounds.size.width 
    self.bounds.size.height