how to set marginTop to the Label in iOS like android

In android we use margin top like this but in ios how to use marginTop in storyboard?? sorry i am new to ios

android:layout_marginTop = "5dp"

2 answers

  • answered 2018-04-14 14:28 J. Doe

    See the picture, it is pretty simple:

    enter image description here

  • answered 2018-04-14 14:28 hardik parmar

    In iOS, we use autolayout constraints. You can assign those in Interface Builder or you can give it programmatically. As @J. Doe suggested, that is how you can assign it in Interface Builder. To assign it programmatically, you can use anchors for deployment target above iOS 10.0 like this:

    let View = UIView()
    View.translatesAutoresizingMaskIntoConstraints = false
    View.topAnchor.constraint(equalTo: anyViewYouWantToAddViewTo.topAnchor, constant: 15).isActive = true
    View.bottomAnchor.constraint(equalTo: anyViewYouWantToAddViewTo.bottomAnchor, constant: 0).isActive = true
    View.leadingAnchor.constraint(equalTo: anyViewYouWantToAddViewTo.leadingAnchor, constant: 0).isActive = true
    View.trailingAnchor.constraint(equalTo: anyViewYouWantToAddViewTo.trailingAnchor, constant: 0).isActive = true