ios - How to add a dashed border for any particular edge of a UIView? -


how can add dashed border in side of uiview only?have referred dashed line border around uiview link, kind of confused while giving path edges of view.ok so, code adding straight line border in particular side of view:

 want output screen

func addrightborder(with color: uicolor, andwidth borderwidth: cgfloat,view:uiview) {              let border = uiview()             border.backgroundcolor = color             border.autoresizingmask = [.flexibleheight, .flexibleleftmargin]             border.frame = cgrect(x: view.frame.size.width - borderwidth, y: 0, width: borderwidth, height: view.frame.size.height)              //border.adddashedline(color: uicolor.red)             border.adddashedline(color: uicolor.red)             view.addsubview(border)         }* 

how can achieve same thing dashed/dotted lines?

in 1 of app, needed similar thing , created uiview extension.

take @ code snippet,

extension uiview { func removedashedline() {     _ = layer.sublayers?.filter({ $0.name == "dashedtopline" }).map({ $0.removefromsuperlayer() }) }  func adddashedline(_ path: uibezierpath ,pattern : [nsnumber] = [1, 5], color: uicolor = uicolor.red) {      self.backgroundcolor = uicolor.clear      let shapelayer: cashapelayer = cashapelayer()     let framesize = self.frame.size     let shaperect = cgrect(x: 0, y: 0, width: framesize.width, height: framesize.height)      shapelayer.name = "dashedtopline"     shapelayer.frame = shaperect     //shapelayer.position = cgpoint(x: framesize.width / 2, y: framesize.height / 2)     shapelayer.fillcolor = uicolor.clear.cgcolor     shapelayer.strokecolor = color.cgcolor     shapelayer.linewidth = 1     shapelayer.linejoin = kcalinejoinround     shapelayer.linedashpattern = pattern      shapelayer.path = nil     shapelayer.path = path.cgpath     self.layer.insertsublayer(shapelayer, at: 0)  } } 

it may not want should you


Comments

Popular posts from this blog

minify - Minimizing css files -

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -