RelativeLayout in IOS


I have an Android app and I need to do it in IOS. In the app there are screens with long forms that occupy much more than the length of the screen, which I do in an xml layout, all with code, using relative layout.

Is there any way in IOS to do it in a similar way? At the moment I have only used the Interface Builder and with that I can not do what I want.

asked by Alex B 28.06.2016 в 11:34

2 answers


First of all, do not try to think like you do when programming for Android when you're programming for iOS, since things work differently.

If as you say, the elements you need to include occupy more of the length of the view, you should use a UIScrollView and within this position them so that regardless of the size of the device, the elements can be seen doing scroll on the screen.

On the other hand, it is not mandatory that you use Interface Builder to create your elements, you can create them programmatically in a very simple way within methods like viewDidLoad of your UIViewController .

You could even use cycles like in this example with Swift :

class MyAwesomeViewController: UIViewController {
    override func viewDidLoad() {

        let numberOfLabels: Int = 100
        let labelHeight: CGFloat = 50

        let myAwesomeScrollView = UIScrollView(frame: view.bounds)
        myAwesomeScrollView.contentSize = CGSizeMake(view.bounds.width, CGFloat(numberOfLabels) * labelHeight)

        for index in 1...numberOfLabels {
            let labelFrame = CGRectMake(0, CGFloat(index - 1) * labelHeight, myAwesomeScrollView.bounds.width, labelHeight)
            let myAwesomeLabel = UILabel(frame: labelFrame)

            myAwesomeLabel.text = "My awesome label \(index)"

answered by 29.06.2016 / 21:28

In iOS the Interface Builder is used, there is no similarity to the Relative Layout of Android . I've made an app in iOS and in Android and I could not use anything from one app to another.

answered by 28.06.2016 в 11:41