Search code examples
swiftxcode6cgrectmake

unable to view the line on swift


I am trying to add a horizontal line that starts from left side of the screen to the right. But the line isn't visible.

let horizontalLine : CGRect = CGRectMake(45, height-50, 45, 55)
var testView : UIView = UIView(frame: horizontalLine)
self.view.addSubview(testView)

Solution

  • Try with this

    let horizontalLine : CGRect = CGRectMake(45, 100-50, 45, 55)
    //check value of height. this height>=(status bar height(20)+navigation bar height (44))
        var testView : UIView = UIView(frame: horizontalLine)
        testView.backgroundColor = UIColor.redColor()
        self.view.addSubview(testView)