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?
-
Did you create the UIView class?Bista– Bista2016-09-12 07:10:27 +00:00Commented Sep 12, 2016 at 7:10
-
@Shai Please try my solution. It may help youMonika Patel– Monika Patel2016-09-12 07:17:44 +00:00Commented Sep 12, 2016 at 7:17
3 Answers
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.
1 Comment
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
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];
}
