2

I created custom UIView with its NIB, in which I want to use as popup in multiple UIViewControllers. How can I add this custom UIView to existing UIViewController, either by SB or programmatically?

2
  • Did you create the UIView class? Commented Sep 12, 2016 at 7:10
  • @Shai Please try my solution. It may help you Commented Sep 12, 2016 at 7:17

3 Answers 3

3
  • Create an XIB file for UIView.

  • Add Labels, buttons to it as per requirements.

  • Create an UIView Class file e.g. Class MyView:UIView.

  • Assign this Class to the UIView via IBInspector.

  • Now create an instance of this class, assign values to the elements.

Sign up to request clarification or add additional context in comments.

1 Comment

The answer might be incomplete, let me know where this got you to?
1

Look at right in show at identity inspector - add uiview class to there. 2.Programatically - Add uiview class header file into view controller class.

    SampleView *view = [[SampleView alloc]initWithFrame:CGRectMake(100, 20, [UIScreen mainScreen].bounds.size.width-200, 80)];
[self.view addSubview:view];

Comments

1

Create one UIViewController and put your custom UIView in that view controller. Add this function in your any static file if your already created other wise add this method in appdelgate.m. AppDelegate.h

@property(strong,nonatomic) BottomPlayerViewVC *nonSystemsController;
-(void)addPlayerView:(UIView*)view;

AppDelegate.m

-(void)addPlayerView:(UIView*)view
{
    [self.nonSystemsController.view removeFromSuperview];
    self.nonSystemsController = [[BottomPlayerViewVC alloc] initWithNibName:@"BottomPlayerViewVC" bundle:nil];
    self.nonSystemsController.view.frame = 'set_your_frame';
    [view addSubview:self.nonSystemsController.view];
}

ViewController1.m

#define AppObj (AppDelegate *)[[UIApplication sharedApplication] delegate]
- (void)viewDidLoad 
{
    [super viewDidLoad];
    [AppObj addPlayerView:self.view];
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.