H Raval H Raval - 23 days ago 6
iOS Question

IOS insert layout programatically

Actually i am an Android App Developer and now I am learning IOS app development.

In android we can create a seperate 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 programatically to another layout.

Is this possible with IOS. If yes then how?

Well i am using Xcode with swift 2.3

Answer

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