Skip to content

Instantly share code, notes, and snippets.

View cybersamx's full-sized avatar

Samuel Chow cybersamx

  • Los Angeles, Ca
  • 01:45 (UTC -07:00)
View GitHub Profile
@cybersamx
cybersamx / UIStretchedButton.m
Last active August 29, 2015 14:04
Create a custom UIButton with a custom background image and stretchable width.
// 1. Create a PNG background image.
// 2. Use UIEdgeInsets to stretch the image eg. 8.0f left and right of rect to remain unstretched
// 3. Make sure the UIButton height is the same as the image height
UIImage *image = [UIImage imageNamed:@"button_background_blue.png"];
UIEdgeInsets insets = UIEdgeInsetsMake(0.0f, 8.0f, 0.0f, 8.0f);
UIImage *stretchedImage = [image resizableImageWithCapInsets:insets];
[self.button setBackgroundImage:stretchedImage forState:UIControlStateNormal];
@cybersamx
cybersamx / UIViewSnapshot.m
Created August 6, 2014 17:39
Create a UIImageView representing a visual snapshot of another UIView object.
- (UIImageView *)createSnapshotFromView:(UIView *view) {
UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
UIImage *snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return [[UIImageView alloc] initWithImage:snapshotImage];
}