Skip to content

Instantly share code, notes, and snippets.

View lsgbhp's full-sized avatar

ShawnLin lsgbhp

  • Shanghai, China
View GitHub Profile
@lsgbhp
lsgbhp / 0_reuse_code.js
Created January 10, 2017 07:47
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
// the space between the image and text
CGFloat spacing = 6.0;
// lower the text and push it left so it appears centered
// below the image
CGSize imageSize = button.imageView.image.size;
button.titleEdgeInsets = UIEdgeInsetsMake(
0.0, - imageSize.width, - (imageSize.height + spacing), 0.0);
// raise the image and push it right so it appears centered
@lsgbhp
lsgbhp / uicolor+createImage.m
Created June 26, 2016 16:10
create uiimage from uicolor
+ (UIImage*)createImageWithColor: (UIColor*) color {
CGRect rect=CGRectMake(0,0, 1, 1);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
@lsgbhp
lsgbhp / UIButton+SwapImageText.m
Last active June 26, 2016 16:09
uibutton put image after text
- (void)swapImageTextPosition {
self.transform = CGAffineTransformScale(self.transform, -1.f, 1.f);
self.titleLabel.transform = CGAffineTransformScale(self.titleLabel.transform, -1.f, 1.f);
self.imageView.transform = CGAffineTransformScale(self.imageView.transform, -1.f, 1.f);
}