1

I have created a custom .xib-file and a custom subclass of UIView. What is the procedure to connect the two?

Meaning that when I set MyCustomClass in the custom class attribute, it turns into my custom .xib-file and acts according to MyCustomClass.swift.

Marmelador
  • 947
  • 7
  • 27

2 Answers2

2

Click on your Xib file and go here and set your custom Class here

Set your custom class name here

elk_cloner
  • 2,049
  • 1
  • 12
  • 13
  • While googling I have found many tutorials that say you need to add code to MyCustomClass.swift in order to load from the .xib. Are they all outdated? – Marmelador Jun 05 '17 at 08:22
  • Dude, I don't know about link what you mentioned. – elk_cloner Jun 05 '17 at 08:29
  • Excuse me. For example here: https://stackoverflow.com/questions/25513271/how-to-initialise-a-uiview-class-with-a-xib-file-in-swift-ios or https://stackoverflow.com/questions/9251202/how-do-i-create-a-custom-ios-view-class-and-instantiate-multiple-copies-of-it-i – Marmelador Jun 05 '17 at 08:31
  • you need to write this in your class. because so far what you did my way is to added the class file with the nib file.But how will you access it from another View contoller? Thats the code you shared. – elk_cloner Jun 05 '17 at 08:36
0

Select Whatever.xib >> Click Show Identity Inspector >> Focus at Custom Class >> Edit Class as MyCustomClass See this example for Test.xib and Test.swift : enter image description hereenter image description here

roy
  • 6,685
  • 3
  • 26
  • 39