开发者

Adding views to a scrolling view

开发者 https://www.devze.com 2022-12-16 17:39 出处:网络
I have a view (myContactViewController.xib) which contains a Scroll View (created in Interface Builder, and which takes takes up the entire height of the window and is 960px in width — ie. 3 x the wi

I have a view (myContactViewController.xib) which contains a Scroll View (created in Interface Builder, and which takes takes up the entire height of the window and is 960px in width — ie. 3 x the width of a single window). I'm using the Scroll View, with paging, for horizontal navigation of three subviews (all three subviews are 320x460, ie. the entire size of the window). I have created these three subviews via Xcode (command-N), and so for each subview I have a .h, .m and .xib. I have used Interface Builder to build the layout (just some text and a picture for now — but, will eventually contains some buttons) for their views.

Programm开发者_Go百科atically, I would like the load these three views into my Scroll View, specifying their location within. The .xibs for each of the views I'd like to load into the scroll view are as follow: myContactSub1.xib, myContactSub2.xib and myContactSub3.xib).

I'm wondering if anyone would be willing to explain how to do this?

Thanks, Kristin.


Sure it's very easy. First set the frame for the subview. The frame specifies where in the superview you want it to appear and is a CGRect. So you might use CGRectMake(0, 0, 320, 460) for the first subview. Then add it to the UIScrollView with addSubview:. Here's an example:

mySubView.frame = CGRectMake(0, 0, 320, 460);
[myScrollView addSubview:mySubView];

This assumes you have a pointer to these views, using IBOutlets. If you need help doing this read up on Xcode Integration

Also take a look at View Geometry

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号