Created
June 18, 2012 15:39
-
-
Save yashigani/2948978 to your computer and use it in GitHub Desktop.
This file contains 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
- (void)sizeToFitWithAnchorPoint:(AnchorPoint)anchorPoint | |
{ | |
CGRect srcFrame = self.frame; | |
[self sizeToFit]; | |
CGRect dstFrame = self.frame; | |
CGPoint p = dstFrame.origin; | |
switch (anchorPoint) { | |
case AnchorPointRightTop: | |
p = CGPointMake( | |
CGRectGetMaxX(srcFrame) - dstFrame.size.width, | |
srcFrame.origin.y | |
); | |
break; | |
case AnchorPointLeftBottom: | |
p = CGPointMake( | |
srcFrame.origin.x, | |
CGRectGetMaxY(srcFrame) - dstFrame.size.height | |
); | |
break; | |
case AnchorPointRightBottom: | |
p = CGPointMake( | |
CGRectGetMaxX(srcFrame) - dstFrame.size.width, | |
CGRectGetMaxY(srcFrame) - dstFrame.size.height | |
); | |
break; | |
case AnchorPointLeftTop: | |
default: | |
break; | |
} | |
dstFrame.origin = p; | |
self.frame = dstFrame; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment