adding uiview as a subview to the main view

前端 未结 3 1979
别跟我提以往
别跟我提以往 2021-01-06 03:10

i want to add an UIView for small size as a subview to existing view.

i have a UIViewController pushed with a nib name which is the main vi

相关标签:
3条回答
  • 2021-01-06 03:30
    UIView *view = [[UIView alloc] init];
    
    0 讨论(0)
  • 2021-01-06 03:31

    UIView needs to be alloc'ed and init'ed with a frame:

    CGRect frame = CGRectMake(x, y, width, height); // Replacing with your dimensions
    UIView *view = [[UIView alloc] initWithFrame:frame];
    
    0 讨论(0)
  • 2021-01-06 03:45

    To add something (rather important) to the answers above;

    CGRect frame = CGRectMake(x, y, width, height); // Replacing with your dimensions
    UIView *view = [[UIView alloc] initWithFrame:frame];
    

    Then, you want to actually add it to the superview (assuming the view is self.view)

    [self.view addSubview:view];
    
    0 讨论(0)
提交回复
热议问题