开发者

How to center UIScrollView inside UIViewController

开发者 https://www.devze.com 2023-03-20 16:06 出处:网络
I\'m currently trying to center a UIScrollView inside of my UIViewController class and am having a problem.

I'm currently trying to center a UIScrollView inside of my UIViewController class and am having a problem.

The UIViewController is inside of a tab bar and a nav bar, so it is 367 pixels tall on iPhone and 320开发者_JAVA百科 pixels wide.

The UIScrollView is placed inside of that UIViewController, and the UIScrollView is being loaded from another UIViewController class responsible for displaying content.

Now, my goal is to make the scrollview 10 pixels less in width than the containing UIViewController so that the scroll view does not take up the width of the screen.

However, in Interface Builder, when I select 300 as my UIScrollView width, and in my implementation file for the containing UIViewController, when I set the width as 300,

[scrollView setContentSize:CGSizeMake(300, 1500)];

the end result is a full-screen scroll view instead of one cut off by 5 at each side.

Any ideas on how to take care of this?

Thanks.


You can use uiscrollview's

@property(nonatomic) UIEdgeInsets contentInset

However, it is possible that when you are using in the class1 the scroll view from the class2, scroll view frame/content size are read from class2 object instead of class1 nib.

0

精彩评论

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

关注公众号