H Raval
H Raval

Reputation: 1903

IOS insert layout programmatically

In android we can create a separate xml layout and can include it in another layout. I want to achieve same in IOS. I want to create a custom layout and want to include it programmatically to another layout.

How to do it with IOS?

I am using Xcode with swift 2.3.

Upvotes: 1

Views: 257

Answers (3)

Dhruv Khatri
Dhruv Khatri

Reputation: 813

Yes you can do it. First of all you have to create simple fileName.swift file

create File

select this one.

swiftFile

Give class Name as your file name (Here i gave sample) and choose UIView (Because we are creating a simple View.) class Name

Now again Create View (it will create a .xib file where you can design your layout)

View Image

Now you select View and create your UI like this.

createView

now open sample.swift (Here) and write simple code.

code file

now you can use this view to add any where in your project. To add this add simple View in any StoryBoard ViewController (Drag and Drop)

storyView

Now Main Step to add your Custom View in your View Select your View from ViewController (where you want to add this) and simple Write class name in identity Inspector.

class Name

Now Simple Run the project and Bingo..

Output

Upvotes: 2

coreDeviOS
coreDeviOS

Reputation: 1538

If you want to build view programmatically you might want to user

https://github.com/SnapKit for swift.

https://github.com/SnapKit/Masonry for objc.

Upvotes: 1

Poles
Poles

Reputation: 3682

In iOS we called them views.

You can use addSubView to add another view inside a view.

Example:

[self.view addSubView: yourcustomView]; //Where self.view is the parent view.

Upvotes: 0

Related Questions