0

am adding a border to my view like this:

func addBottomBorderWithColor(color: UIColor, width: CGFloat) {
    let border = CALayer()
    border.backgroundColor = color.cgColor
    border.frame = CGRect(x: 0, y: self.frame.size.height, width: self.frame.size.width, height: width)
    self.layer.addSublayer(border)
}

but strangley this works fine on Iphone 7 but in iphone 7 plus .. i will get this result:

screenshot

as you can see there's a space at the beginning of the view's border.. why?

same thing is happening with view's shadow .. am doing it like this:

     func dropShadow(scale: Bool = true) {
    layer.shadowColor = UIColor.lightGray.cgColor
    layer.shadowOpacity = 0.5
    layer.shadowOffset = CGSize.zero
    layer.shadowRadius = 1
    layer.shadowPath = UIBezierPath(rect: bounds).cgPath
    layer.shouldRasterize = true
    layer.rasterizationScale = scale ? UIScreen.main.scale : 1
}

and getting space at the end of the view on iphone 7 plus

enter image description here

how to solve it?

Joakim Danielson
  • 43,251
  • 5
  • 22
  • 52
mrs.bassim
  • 469
  • 2
  • 7
  • 16

2 Answers2

0

it means your UI Is not updated , call in viewdidAppear or force to update the UI in mainthread on viewdidload using

DispatchQueue.main.async {
   //call your addBottomBorderWithColor
}
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
0

Try calling the addBottomBorderWithColor in:

 override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()


}

The UI gets updated according to the constraints after ViewDidLoad.

Amit
  • 4,837
  • 5
  • 31
  • 46