Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Write a category on UIView.</p> <p>In Xcode, go File -> New -> File and then select "Objective-C Category" from the Cocoa Touch row in the iOS section. Ensure the category is on UIView, give it a name and you're away.</p> <p>From here, you can add properties or even instance methods, which, assuming you import the category in your app's prefix file, all classes that inherit from UIView will have access to.</p> <p>EDIT: I have not worked with associated objects. This is a really simple example using pre-defined properties that already exist in the object, using my own properties to simplify their retrieval.</p> <p>The OP has not stated what kind of property they wish to add to UIView, which is why I made the assumption that a category would suffice. I am certain you are all correct with the comments below re: data storage on a truly custom property.</p> <p>I do not appreciate downvotes when in fact the objective of the OP has not been made quite so clear, regarding the usage of their "newProperty."</p> <p>eg: Category on UIView called Position. (UIView+Position)</p> <pre><code>UIView+Position.h @interface UIView (Position) -(CGFloat)left; -(CGFloat)right; -(CGFloat)top; -(CGFloat)bottom; @property (nonatomic) CGFloat left; @property (nonatomic) CGFloat right; @property (nonatomic) CGFloat top; @property (nonatomic) CGFloat bottom; @end UIView+Position.m #import "UIView+Position.h" @implementation UIView (Position) -(CGFloat)left { return self.frame.origin.x; } -(CGFloat)right { return self.frame.origin.x + self.frame.size.width; } -(CGFloat)top { return self.frame.origin.y; } -(CGFloat)bottom { return self.frame.origin.y + self.frame.size.height; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload