Created
February 20, 2013 17:01
-
-
Save McZonk/4997099 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIPCenteredScrollView.m | |
// Plus | |
// | |
// Created by Maximilian Christ on 5/30/12. | |
// Copyright (c) 2012 mczonk.de. All rights reserved. | |
// | |
#import "UIPCenteredScrollView.h" | |
#import "NSArray+NSPFirstObject.h" | |
@implementation UIPCenteredScrollView | |
- (void)layoutSubviews { | |
[super layoutSubviews]; | |
CGSize boundsSize = self.bounds.size; | |
UIView* centerView = self.subviews.firstObject; | |
CGRect frameToCenter = centerView.frame; | |
if(frameToCenter.size.width < boundsSize.width) { | |
frameToCenter.origin.x = (boundsSize.width - frameToCenter.size.width) * 0.5f; | |
} else { | |
frameToCenter.origin.x = 0; | |
} | |
if(frameToCenter.size.height < boundsSize.height) { | |
frameToCenter.origin.y = (boundsSize.height - frameToCenter.size.height) * 0.5f; | |
} else { | |
frameToCenter.origin.y = 0; | |
} | |
centerView.frame = frameToCenter; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment