initWithFrame and loadNibNamed not working together?

374 Views Asked by At

I'm using Paged UIScrollView with an embedded UIPageControl like explained at https://github.com/romaonthego/REPagedScrollView.

The code works fine when I use

UIView *page1 = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 280, self.view.frame.size.height - 40)];
page1.backgroundColor = [UIColor lightGrayColor];
[scrollView addPage:page1];

But I need to use a nib file for my project. I'm calling it like :

UIView *page1 = [[[NSBundle mainBundle] loadNibNamed:@"mySubViewController" owner:self options:nil] objectAtIndex: 0];
page1 = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 280, self.view.frame.size.height - 40)];
page1.backgroundColor = [UIColor lightGrayColor];
[scrollView addPage:page1];

Which almost works fine, I can call the view, only problem is that the view does not listen to initWithFrame:CGRectMake, it loads full screen and I can not see the page control anymore to navigate.

Autolayout is set to off.

Could anyone point me where I am wrong here ? What I could do to solve this issue ?

Best regards, David

1

There are 1 best solutions below

1
On

You can set frame of any view manually with method -(void)setFrame:(CGRect)frame

    UIView *page1 = [[[NSBundle mainBundle] loadNibNamed:@"mySubViewController" owner:self options:nil] objectAtIndex: 0];
    page1.backgroundColor = [UIColor lightGrayColor];
    page1.frame = CGRectMake(20, 20, 280, self.view.frame.size.height - 40);
    [scrollView addPage:page1];