How to embed a custom view xib in a storyboard scene?

前端 未结 11 566
生来不讨喜
生来不讨喜 2021-01-29 21:33

I\'m relatively new in the XCode/iOS world; I\'ve done some decent sized storyboard based apps, but I didn\'t ever cut me teeth on the whole nib/xib thing. I want to use the sam

11条回答
  •  遇见更好的自我
    2021-01-29 22:24

    You just have to drag and drop UIView in your IB and outlet it and set

    yourUIViewClass  *yourView =   [[[NSBundle mainBundle] loadNibNamed:@"yourUIViewClass" owner:self options:nil] firstObject];
    [self.view addSubview:yourView]
    

    enter image description here

    Step

    1. Add New File => User Interface => UIView
    2. Set Custom Class - yourUIViewClass
    3. Set Restoration ID - yourUIViewClass
    4. yourUIViewClass *yourView = [[[NSBundle mainBundle] loadNibNamed:@"yourUIViewClass" owner:self options:nil] firstObject]; [self.view addSubview:yourView]

    Now you can customize view as you want.

提交回复
热议问题