iOS Storyboard: how do you edit a content view lar

2019-04-09 03:09发布

I have a view that is larger than screen, I need to put it in a UIScrollView.

So I first add an UIViewController to story board, then, I add a UIScrollView to the root view of my view controller, then when I add subviews of UIScrollView, but I can't add them outside the scrollview area I can see, how to solve this problem?

3条回答
对你真心纯属浪费
2楼-- · 2019-04-09 03:51

Edit 1:

1) put your subview into scrollview's visible area

2) change frame of the new subview as you wish

change frame

3) change contentSize property of scrollview with runtime attributes

runtime attributes

Edit 2: u can create a new view with xib, which contains all your subviews, and then add this view on scrollview OR u can use storyboard's Container View like this:

enter image description here

p.s.: don't forget about contentSize (point 3 in my first edit), but if you are using auto-layout, you need to set it programmatically like this:

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    _scrollView.contentSize = CGSizeMake(320, 250);
}
查看更多
戒情不戒烟
3楼-- · 2019-04-09 04:03
  1. put a scroll view in the view controller ,and put a view inside the scroll view named containerView.
  2. design the big content in another view controller (named bigContentView)
  3. in code ,view load event ,

a. get the bigContentView by storyboard Id. ( get the controller and use controller.view)

b. create the outlet to the containerView.

c. update the containerView's frame according your requirement.(update the width and height)

d. bigContentView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;

e. containerView addSubView:bigContentView.

查看更多
欢心
4楼-- · 2019-04-09 04:11

Change the simulated size of the view controller to Freeform and then you can set the size to whatever you want. After editing, you may want to set it back.

freeform

查看更多
登录 后发表回答