Skip to content

Instantly share code, notes, and snippets.

@yashigani
Created June 18, 2012 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yashigani/2948978 to your computer and use it in GitHub Desktop.
Save yashigani/2948978 to your computer and use it in GitHub Desktop.
- (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