ios - UITextField set border color using storyboard -
ios - UITextField set border color using storyboard -
i'd set border color using storyboard if possible. i've seen reply here: uitextfield border color
and followed reply in storyboard:
all properties set, textfield doesn't show border. suggestions?
as bogdan pointed out it's true can't find layer.bordercolor property in storyboard it's run time thing.
however still can set bordercolor without using ib_designable, on view(or uiview subclass) little bit of coding.
below steps how accomplish it,
create category on calayer class. declare property of type uicolor suitable name, i'll name borderuicolor . write setter , getter property. in 'setter' method set "bordercolor" property of layer new colors cgcolor value. in 'getter' method homecoming uicolor layer's bordercolor.p.s: remember, categories can't have stored properties. 'borderuicolor' used calculated property, reference accomplish we're focusing on.
please have @ below code sample;
objective c:
interface file:
#import <quartzcore/quartzcore.h> #import <uikit/uikit.h> @interface calayer (borderproperties) // assigns cgcolor bordercolor. @property (nonatomic, assign) uicolor* borderuicolor; @end
implementation file:
#import "calayer+borderproperties.h" @implementation calayer (borderproperties) - (void)setborderuicolor:(uicolor *)color { self.bordercolor = color.cgcolor; } - (uicolor *)borderuicolor { homecoming [uicolor colorwithcgcolor:self.bordercolor]; } @end
swift 2.0:
extension calayer { var borderuicolor: uicolor { set { self.bordercolor = newvalue.cgcolor } { homecoming uicolor(cgcolor: self.bordercolor!) } } }
and go storyboard/xib, follow remaining steps;
click on view object want set border color. click on "identity inspector"(3rd left) in "utility"(right side of screen) panel. under "user defined runtime attributes", click on "+" button add together key path. set type of key path "color". enter value key path "layer.borderuicolor". [remember should variable name declared in category, not bordercolor here it's borderuicolor]. finally chose whatever color want.edit: you've set layer.borderwidth property value @ to the lowest degree 1 see border color.
build , run. happy coding. :)
ios storyboard uitextfield
Comments
Post a Comment