0

Im trying to detect which size of the phone the user got and set the scrollview length to appropriate size. For example if the user is using an iPhone plus the scroll length should be shorter then if the user is using an iPhone 5

   - (void)scrollViewDidScroll:(UIScrollView *)sender {
        if (!pageControlBeingUsed) {
            // Switch the indicator when more than 50% of the previous/next page is visible
            CGFloat pageWidth = self.scroll2.frame.size.width;
            int page = floor((self.scroll2.contentOffset.x - pageWidth / 3) / pageWidth) + 1;
            self.pageControl.currentPage = page;
        }
    }

    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view from its nib.

        if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
            if ([[UIScreen mainScreen] scale] == 2.0) {

                if([UIScreen mainScreen].bounds.size.height == 667.0){

                    self.scroll2.contentSize = CGSizeMake(300, 100);
                    // iPhone retina-4.7 inch(iPhone 6)
                }
                else if([UIScreen mainScreen].bounds.size.height == 568.0){

                    self.scroll2.contentSize = CGSizeMake(300, 5500);
                    // iPhone retina-4 inch(iPhone 5 or 5s)
                }
                else{
                    // iPhone retina-5 inch inch(iPhone Plus)
                }
            }

        }
  • Possible duplicate of [How to get the screen width and height in iOS?](https://stackoverflow.com/questions/5677716/how-to-get-the-screen-width-and-height-in-ios) – Tamás Sengel Sep 28 '17 at 15:13

1 Answers1

0

You can achieve this auto layout.Just put you all content in a UIView and add this UIView inside scroll view with five constraint

  1. Fix Height
  2. Top
  3. Bottom
  4. Leading
  5. Trailing

After that you can achieve the solution without headache of checking screen size. If you are new at auto layout than go through this tutorial https://spin.atomicobject.com/2014/03/05/uiscrollview-autolayout-ios/

Pardeep Bishnoi
  • 161
  • 1
  • 7