ios - Swift: add custom view inside CALayer -


I am trying to add a custom view inside the CALayer.

And I want to put some buttons and labels inside, but I'm afraid I am not able to do this. I am creating CALabel like this:

  func addRectangleToLayer (x: CGFloat, y: CGFloat, width: CGFloat, height: CGFloat, layer: CALayer, index: UInt32) {var sublayer = CALayer () Sublayer.backgroundColor = UIColor.whiteColor (). CGColor sublayer.shadowOffset = CGSizeMake (0, 3); Sublayer.shadowRadius = 5.0; Sublayer.shadowColor = UIColor.blackColor (). CGColor sublayer.shadowOpacity = 0.8; Sublayer.cornerRadius = 12.0; Sublayer.frame = CGRectMake (X, Y, width, height); Sublayer.borderColor = UIColor.blackColor () CGColor; Sublayer.borderWidth = 0.5; // Give an example label = UILabel () label.text = "LOREN" sublayer.contents = label layer.insertSublayer (sublayer, at index: index)}  

Is it possible to do this I want

Many thanks and sorry for my English level

If you UIView , you will have access to its Layer property for this purpose:

  label = UILBL () label .text = " LOREN "var sublayer = label.layer; // .. Rest of your layer initial sublayer.backgroundColor = UIColor.whiteColor (). CGColor sublayer.shadowOffset = CGSizeMake (0, 3); Sublayer.shadowRadius = 5.0; Sublayer.shadowColor = UIColor.blackColor (). CGColor sublayer.shadowOpacity = 0.8; Sublayer.cornerRadius = 12.0; Sublayer.frame = CGRectMake (X, Y, width, height); Sublayer.borderColor = UIColor.blackColor () CGColor; Sublayer.borderWidth = 0.5; // The original source initialization layer has ended. InsertsBlare (sublighter, index: index)  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -