Convert UIViewController to UIScrollViewController

I'm new to the iPad developer,

I made one registration form in my application, when I see my application in Portraitmode, I can see the entire form without scrolling, but when I see the same form in mode Landscape, I can not see the part that is at the bottom of the page, for this there should be a scroll there to see the bottom.

s: In my .hfile, when I replace

@interface ReminderPage : UIViewController{
...
...
}

:UIViewController with :UIScrollView

and then when I add a tag to my file .mlike

UILabel *Lastpaidlbl = [[[UILabel alloc] initWithFrame:CGRectMake(70 ,400, 130, 50)]autorelease];
    Lastpaidlbl.backgroundColor = [UIColor greenColor];
    Lastpaidlbl.font=[UIFont systemFontOfSize:20];
    Lastpaidlbl.text = @"Lastpaid on :";
    [self.view addSubview:Lastpaidlbl];

I get an error in the last line. Property view not found on object of type classname. I can not add a label in my opinion.

Any help would be appreciated.

+5
5

UIViewController UIScrollView, . , , :

:

[self.view addSubview:Lastpaidlbl];

, self UIViewController; UIScrollView, :

[self addSubview:Lastpaidlbl];

, , .

:

  • UIScrollView ( );

  • UIView (, ) ;

  • contentSize , UIView, .

( , self.view); , :

      1. UIScrollView* scrollView = <alloc/init>

      2. [self.view addSubview:scrollView]; (in your  controller)

      3. [scrollView addSubview:<label>]; (for all of your labels and fields).

      4. scrollView.contentSize = xxx;

, .

+4

, , UIScrollView, UIView. Xcode 4.6.3, , :

  • Interface Builder - UIView.
  • Xcode " | | ".

, UIView, - UIView UIScrollView .

+6

, UIComponents UIScrollview, .

. , .

0

UIScrollView, self.view, self - (). scrollview, ivar contentSize ( , ). , - > /.

0

First create a scrollview

 UIScrollView *  scr=[[UIScrollView alloc] initWithFrame:CGRectMake(10, 70, 756, 1000)];
    scr.backgroundColor=[UIColor clearColor];
    [ self.view addSubview:scr];

second

change [self.view addSubview:Lastpaidlbl];

      to

[scr addSubview: Lastpaidlbl];

third

set height depends on content

UIView *view = nil;

 NSArray *subviews = [scr subviews];


 CGFloat curXLoc = 0;

    for (view in subviews)
    {
        CGRect frame = view.frame;
        curXLoc += (frame.size.height);
    }
       // set the content size so it can be scrollable
    [scr setContentSize:CGSizeMake(756, curXLoc)];

Finally

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Override to allow orientations other than the default portrait orientation.
    if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight) {
        self.scr.frame = CGRectMake(0, 0, 703,768);    

        } else {
        self.scr.frame = CGRectMake(0, 0, 768, 1024);
        }


    return YES;
}
0
source

All Articles