UIScrollView - add a Subview so that it centers horizontally and vertically

How to add UIImageView code to UIScrollView so that it appears in the center.

The scroll view fills a large area; the UIImage view is approximately 40% of the average size.

+3
source share
2 answers

How about imageView.center = scrollView.center

+6
source

How about what's around the lines ...

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];
+1
source

All Articles