ios - inner shadow effect UIView -


i want add inner shadow uilabel

picture:

picture

reference form inner shadow effect on uiview layer?

    let display = uilabel()  func setbackgroundlayer () {     let backgroundlayer = cagradientlayer()     backgroundlayer.frame = view.bounds     backgroundlayer.colors = [uicolor(white:1,alpha:0.5).cgcolor,uicolor(white:0.5,alpha:0.5).cgcolor]     view.layer.insertsublayer(backgroundlayer, at: 0) }  func setdisplay() {     let xratio = view.bounds.width/8     display.frame = cgrect(x:xratio,y:80,width:xratio*6,height:xratio*2)     display.backgroundcolor = uicolor(red:204/255,green:203/255,blue:181/255,alpha:1)     view.addsubview(display)  }  func displayinnershadow() {       let shadowlayer = cashapelayer()     shadowlayer.frame = view.bounds      let path = cgmutablepath()     path.addrect(display.frame.insetby(dx: -20, dy: -20))     path.addrect(display.frame)       shadowlayer.fillrule = kcafillruleevenodd     shadowlayer.path = path      shadowlayer.shadowcolor = uicolor(white:0,alpha:1).cgcolor     shadowlayer.shadowoffset = cgsize(width:0,height:0)     shadowlayer.shadowopacity = 1     shadowlayer.shadowradius = 5      view.layer.insertsublayer(shadowlayer, at: 1)   }    override func viewwillappear(_ animated: bool) {     super.viewwillappear(animated)     setbackgroundlayer()     setdisplay()     //displayinnershadow() } 

i got result:

result picture

why isn't working , how set fill color?

try this

let display = uilabel()  func setbackgroundlayer () {     let backgroundlayer = cagradientlayer()     backgroundlayer.frame = view.bounds     backgroundlayer.colors = [uicolor(white:1,alpha:0.5).cgcolor,uicolor(white:0.5,alpha:0.5).cgcolor]     view.layer.insertsublayer(backgroundlayer, at: 0) }  func setdisplay() {     let xratio = view.bounds.width/8     display.frame = cgrect(x:xratio,y:80,width:xratio*6,height:xratio*2) 

set layer background color instead of display.backgroundcolor

    display.layer.backgroundcolor = uicolor(red:204/255,green:203/255,blue:181/255,alpha:1).cgcolor     view.addsubview(display)  }  func displayinnershadow() {      let innershadowlayer = calayer()     innershadowlayer.frame = display.bounds     let path = uibezierpath(rect: innershadowlayer.bounds.insetby(dx: -20, dy: -20))     let innerpart = uibezierpath(rect: innershadowlayer.bounds).reversing()     path.append(innerpart)     innershadowlayer.shadowpath = path.cgpath     innershadowlayer.maskstobounds = true     innershadowlayer.shadowcolor = uicolor.black.cgcolor     innershadowlayer.shadowoffset = cgsize.zero     innershadowlayer.shadowopacity = 1     innershadowlayer.shadowradius = 5     display.layer.addsublayer(innershadowlayer) }   override func viewwillappear(_ animated: bool) {     super.viewwillappear(animated)     setdisplay()     setbackgroundlayer()     displayinnershadow()  } 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -