Saturday, 15 February 2014

ios - dashed border UIImageView swift -



ios - dashed border UIImageView swift -

i'm trying add together dashed border using calayer on uiimageview. i've found method, working in swift , how can convert swift? o have imageview has border best solution utilize calayer, similar? how can obtain this

obj-c code swift?

- (cashapelayer *) adddashedborderwithcolor: (cgcolorref) color { cashapelayer *shapelayer = [cashapelayer layer]; cgsize framesize = self.size; cgrect shaperect = cgrectmake(0.0f, 0.0f, framesize.width, framesize.height); [shapelayer setbounds:shaperect]; [shapelayer setposition:cgpointmake( framesize.width/2,framesize.height/2)]; [shapelayer setfillcolor:[[uicolor clearcolor] cgcolor]]; [shapelayer setstrokecolor:color]; [shapelayer setlinewidth:5.0f]; [shapelayer setlinejoin:kcalinejoinround]; [shapelayer setlinedashpattern: [nsarray arraywithobjects:[nsnumber numberwithint:10], [nsnumber numberwithint:5], nil]]; uibezierpath *path = [uibezierpath bezierpathwithroundedrect:shaperect cornerradius:15.0]; [shapelayer setpath:path.cgpath]; homecoming shapelayer; }

ok, in custom view class:

class dashedborderview: uiview { allow _border = cashapelayer() required init?(coder adecoder: nscoder) { super.init(coder: adecoder) setup() } init() { super.init(frame: cgrectzero) setup() } func setup() { _border.strokecolor = uicolor.whitecolor().cgcolor _border.fillcolor = nil _border.linedashpattern = [4, 4] self.layer.addsublayer(_border) } override func layoutsubviews() { super.layoutsubviews() _border.path = uibezierpath(roundedrect: self.bounds, cornerradius:8).cgpath _border.frame = self.bounds } }

ios objective-c iphone swift uiimageview

No comments:

Post a Comment