Andrew Lauer Barinov
Andrew Lauer Barinov

Reputation: 5754

Setting size property in UIScrollview

I would like to create a scrollview inside of another view. I put a UIScrollview element in IB and declared a UIScrollview in my view controller file that is associated with the main view. I also declared it a property in the view controller header file and synthesized in the corresponding implementation file.

Do I set the size of the scrollview in the app delegate or in the view controller? If I set it in view controller do I still have to do the allocation and initialization commands for that instance? Or do I rely on the getter and setter methods that exist as a result of the scrollview being a property?

I should add that I only want the scrollview to occupy a part of the main view.

Here's my viewDidLoad method:

- (void)viewDidLoad
{
    [super viewDidLoad];

    [scrollView setFrame:CGRectMake(0, 44, 768, 1000)];
    [scrollView setContentSize:CGSizeMake(768, 1000)];
    // Do any additional setup after loading the view, typically from a nib.
}

The actual size of the UIScrollview in IB is 768 by 804, there should be a vertical scrollbar present (some of the UI elements in the scrollview are clipped, so there should definitely be a scrollbar if this view is set up correctly.)

Upvotes: 0

Views: 589

Answers (1)

Srikar Appalaraju
Srikar Appalaraju

Reputation: 73718

Yes you can set the frame property of the scrollView instance using setFrame.

i.e. irrespective of what frame size you have defined in IB, using [scrollView setFrame:CGFrameMake()]; you can redefine the exact width, height & x, y coordinates.

In fact this is how one goes about creating a dynamic view in iOS.

Once you are exiting this view entirely make sure you dealloc & release this IB instance since it would have been defines as retain.

Upvotes: 1

Related Questions