ios - UIButton with IB_DESIGNABLE throws runtime attribute warning and does not render in Interface Builder -
ios - UIButton with IB_DESIGNABLE throws runtime attribute warning and does not render in Interface Builder -
i'm running xcode 6.1 , have been using ib_designable ibinspectable quite few projects of sudden doesn't work anymore. have created subclassed buttons arrange image , title vertically centred above each other , enable user set border width , color through ib ibinspectable.
the next warning logged , there no preview available of code in drawrect:
warning: ib designables: ignoring user defined runtime attribute key path "spacingbetweenlabelandimage" on instance of "uibutton". nail exception when attempting set value: [<uibutton 0x7f9278591260> setvalue:forundefinedkey:]: class not key value coding-compliant key spacingbetweenlabelandimage. still, runtime renders intended render , honours same custom spacing i've added through ib.
here's code of menubutton rearranges button , title:
#import "hamburgerbutton.h" ib_designable @interface hamburgerimagebutton : hamburgerbutton @property ibinspectable cgfloat spacingbetweenlabelandimage; @end implementation:
#import "hamburgerimagebutton.h" @implementation hamburgerimagebutton - (void)drawrect:(cgrect)rect { [super drawrect:rect]; cgsize imagesize = self.imageview.frame.size; cgsize titlesize = self.titlelabel.frame.size; // move label left , image right half width cgfloat leftinset = titlesize.width / 2; cgfloat rightinset = imagesize.width / 2; cgfloat halfspacing = self.spacingbetweenlabelandimage == 0 ? 0 : self.spacingbetweenlabelandimage / 2; cgfloat topinset = imagesize.height / 2 + halfspacing; cgfloat bottominset = titlesize.height / 2 + halfspacing; uiedgeinsets imageinsets = uiedgeinsetsmake(-bottominset, leftinset, bottominset, -leftinset); uiedgeinsets titleinsets = uiedgeinsetsmake(topinset, -rightinset, -topinset, rightinset); self.imageedgeinsets = imageinsets; self.titleedgeinsets = titleinsets; } @end you've noticed inherits hamburgerbutton. basic hamburger button not have image , draws border around button. basic hamburger button has same problem: not draw it's border in drawrect in ib , has same type of errors. here's code sake of completeness:
#import <uikit/uikit.h> ib_designable @interface hamburgerbutton : uibutton @property ibinspectable cgfloat borderwidth; @property ibinspectable uicolor *bordercolor; @end implementation:
#import "hamburgerbutton.h" #import <quartzcore/quartzcore.h> @implementation hamburgerbutton - (void)copyinspectables { self.layer.borderwidth = self.borderwidth; self.layer.bordercolor = self.bordercolor.cgcolor; } - (void)drawrect:(cgrect)rect { [self copyinspectables]; } @end i don't understand why throws warning , nil else. didn't alter did. i've checked storyboard, it's ios 7 , up, meant run in xcode 6 (latest).
it complains not beingness able find value on uibutton , that's bit weird because i've subclassed it.
update: changed around , worked. craps out again, without changing else. think there's bug in xcode 6.1... :/
i have been working extensively live views since it's introductions , lot of new features in xcode initially, has flaws. still lot , hope improved in newer versions.
cause:live views work @property properties special ib_designable tag give ui class attributes can approach via user defined runtime attributes set through attributes inspector. see properties exist in identity inspector. root cause of problem cannot map user defined runtime attributes anymore exposed properties.
as open storyboard or xib uses ib_designable, xcode recompile screen @ every alter if have "automatically refresh views" turned on. since code influences ui doesn't have alter in interface builder per se.
with simpler projects on faster machines works pretty bulk of time. larger projects have more ib_designable cpu doesn't have plenty capacity maintain , sort of time-out error while rendering ui. cause of "warning: ib designables: ignoring user defined runtime attribute key path "spacingbetweenlabelandimage" on instance of "uibutton". nail exception when attempting set value: [ setvalue:forundefinedkey:]: class not key value coding-compliant key spacingbetweenlabelandimage." error.
it not update ui anymore custom code. not problem when run though, because @ run time reflect changes.
another cause can code doesn't compile when tries compile in background. inevitable when working on code triggers well.
solution:we need create sure custom view class compiles 1 time again properties can set via interface builder
while in storyboard, go "editor" in top bar menu deselect "automatically refresh views" if still turned on close storyboard tabs rebuild project fix build errors if any re-open storyboard. go "editor" 1 time again , click "refresh views"the warnings should gone , if worked before see custom view code 1 time again well.
after comment below sunkas: it's thought clean solution thoroughly in case of weird problems persist.
ios objective-c uibutton interface-builder xcode6
Comments
Post a Comment