{"id":4644,"date":"2014-03-30T14:15:32","date_gmt":"2014-03-30T14:15:32","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/trouble-with-uiappearance-and-uibutton-subclassing-collection-of-common-programming-errors\/"},"modified":"2014-03-30T14:15:32","modified_gmt":"2014-03-30T14:15:32","slug":"trouble-with-uiappearance-and-uibutton-subclassing-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/trouble-with-uiappearance-and-uibutton-subclassing-collection-of-common-programming-errors\/","title":{"rendered":"trouble with UIAppearance and UIButton subclassing-Collection of common programming errors"},"content":{"rendered":"<p>I have a custom button, that is just a standard UIButton, but with a CAGradientLayer added in.<\/p>\n<p>In my custom button, I have defined two properties:<\/p>\n<pre><code>@property (nonatomic, strong) UIColor* topColor UI_APPEARANCE_SELECTOR;\n@property (nonatomic, strong) UIColor* bottomColor UI_APPEARANCE_SELECTOR;\n<\/code><\/pre>\n<p>If those two values get set, the my button draws itself with a nice linear gradient. Works great.<\/p>\n<p>I also like to put as much into InterfaceBuilder as possible. So, on some of these buttons, in IB&#8217;s &#8220;Identity Inpsector&#8221; I add in &#8220;User Defined Runtime Attributes&#8221; for these properties. Again, works great.<\/p>\n<p>Next, I thought I&#8217;d try using UIAppearance proxies. Most of my custom gradient buttons all have the same colors. But there are a few that are different. So, I figured what I would do is use the appearance-proxy stuff to set the default colors for this class, and then for any buttons that are different, I could just set their values in IntefaceBuilder. This fails.<\/p>\n<p>Apparently, what&#8217;s happening is that it&#8217;s reading the runtime attributes from my storyboard file first, but afterwards those values get overwritten by the appearance proxy. I wouldn&#8217;t expect this to work this way, but it does.<\/p>\n<p>Any tips on how to accomplish this? Or should I just give up on the runtime attributes thing?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have a custom button, that is just a standard UIButton, but with a CAGradientLayer added in. In my custom button, I have defined two properties: @property (nonatomic, strong) UIColor* topColor UI_APPEARANCE_SELECTOR; @property (nonatomic, strong) UIColor* bottomColor UI_APPEARANCE_SELECTOR; If those two values get set, the my button draws itself with a nice linear gradient. Works [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4644","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4644","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4644"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4644\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4644"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4644"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4644"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}