2

I created a UIView with red background color, and a white border of 1pt width with following code.:

let myView = UIView(frame: CGRect(x: 100, y: 100, width: 20, height: 20))
self.view.addSubview(myView)
myView.backgroundColor = UIColor.red
myView.layer.borderColor = UIColor.white.cgColor
myView.layer.borderWidth = 1
myView.layer.cornerRadius = 10

But the myView rendered with a red outline, how to get rid of it? A enlarged screenshot is attached.

Below is the enlarged screenshot

yzyanchao
  • 105
  • 6

1 Answers1

0

It's not answer of your question

But you can make it better if you create another view and add it as a subview to your main view:

let myView = UIView(frame: CGRect(x: 100, y: 100, width: 20, height: 20))

let redView = UIView(frame: CGRect(x: 0, y: 0, width: 20, height: 20))


redView.backgroundColor = UIColor.red
myView.layer.borderColor = UIColor.white.cgColor
myView.layer.borderWidth = 1
redView.layer.borderColor = UIColor.white.cgColor
redView.layer.borderWidth = 1

myView.addSubview(redView)
self.view.addSubview(myView)

myView.layer.cornerRadius = 10
myView.clipsToBounds = true

And result will be:

enter image description here

Arash Etemad
  • 1,827
  • 1
  • 13
  • 29