开发者

UIScrollView - Add Subview so that it's centered Horizontal and Vertical

开发者 https://www.devze.com 2023-03-05 02:37 出处:网络
How do I add, in code, a UIImageView to a UISc开发者_运维技巧rollView so that it appears in the center.

How do I add, in code, a UIImageView to a UISc开发者_运维技巧rollView so that it appears in the center.

The scroll view fills a large area, the UIImage view is about 40% the size on average.


How about imageView.center = scrollView.center


What about something around the lines of...

int size = 20;

UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((scrollView.center.x - (size / 2)), (scrollView.center.y - (size / 2)), size, size)];

[scrollView addSubview:imageView];
0

精彩评论

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