Skip to content

Instantly share code, notes, and snippets.

View yuanhao's full-sized avatar

Yuanhao Li yuanhao

  • Germany
View GitHub Profile
@yuanhao
yuanhao / gist:2b2cd736b4e630c09052
Last active August 29, 2015 14:17
NSLocale.preferredLanguages()[0]
简体中文 zh-Hans
English en
繁体中文 zh-Hant
繁体中文香港 zh-HK
日本语 ja
韩国 ko
<CTFontDescriptor: 0x7fbeca6404e0>{attributes = <CFBasicHash 0x7fbecc9c7af0 [0x107bc6eb0]>{type = mutable dict, count = 8,
#include <iostream>
#include <CoreText/CTFont.h>
#include <CoreText/CTFontCollection.h>
#include <CoreFoundation/CFString.h>
#include <CoreFoundation/CFBase.h>
void callBack(const void *value, void *context) {
CTFontDescriptorRef pDesc = static_cast<CTFontDescriptorRef>(value);
CFStringRef pFamilyName = (CFStringRef)CTFontDescriptorCopyAttribute(pDesc, kCTFontFamilyNameAttribute);
@yuanhao
yuanhao / gist:02be1f42755586b6348d
Created March 8, 2015 16:38
Downloadable font names iOS 8
Optional(Xingkai SC)
Optional(STXingkai-SC-Bold)
Optional(Xingkai SC)
Optional(STXingkai-SC-Light)
Optional(Wawati SC)
Optional(DFWaWaSC-W5)
@yuanhao
yuanhao / CIFilters
Created March 2, 2015 21:54
CIFilter for Still Image
CIAccordionFoldTransition
CIAdditionCompositing
CIAffineClamp
CIAffineTile
CIAffineTransform
CIAreaHistogram
CIAztecCodeGenerator
CIBarsSwipeTransition
CIBlendWithAlphaMask
CIBlendWithMask
@yuanhao
yuanhao / gist:e91d05721989878f03e5
Created January 16, 2015 18:14
NSStringDrawingOptions
let options = unsafeBitCast(NSStringDrawingOptions.UsesLineFragmentOrigin.rawValue | NSStringDrawingOptions.UsesFontLeading.rawValue,
NSStringDrawingOptions.self)
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGRect rect = CGRectMake(250,61 ,410, 255);
CGImageRef imageRef = CGImageCreateWithImageInRect([viewImage CGImage], rect);
+ (UIImage *) imageWithView:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0f);
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO];
UIImage * snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return snapshotImage;
}
+ (UIImage*)imageWithImage:(UIImage*)image
scaledToSize:(CGSize)newSize;
{
UIGraphicsBeginImageContext( newSize );
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
UIView* captureView = self.view;
/* Capture the screen shoot at native resolution */
UIGraphicsBeginImageContextWithOptions(captureView.bounds.size, captureView.opaque, 0.0);
[captureView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
/* Render the screen shot at custom resolution */
CGRect cropRect = CGRectMake(0 ,0 ,1435 ,1435);
- (UIImage *)captureView {
float imageScale = sqrtf(powf(faceImageView.transform.a, 2.f) + powf(faceImageView.transform.c, 2.f));
CGFloat widthScale = faceImageView.bounds.size.width / faceImageView.image.size.width;
CGFloat heightScale = faceImageView.bounds.size.height / faceImageView.image.size.height;
float contentScale = MIN(widthScale, heightScale);
float effectiveScale = imageScale * contentScale;
CGSize captureSize = CGSizeMake(enclosingView.bounds.size.width / effectiveScale, enclosingView.bounds.size.height / effectiveScale);