Skip to content

Instantly share code, notes, and snippets.

View zengyun-hacker's full-sized avatar
🎯
Focusing

Zeng Yun zengyun-hacker

🎯
Focusing
  • Alibaba Inc
  • Hangzhou, Zhejiang, China
View GitHub Profile
@zengyun-hacker
zengyun-hacker / .arclint
Created November 8, 2016 09:54
arclint for ios
{
"linters": {
"spelling": {
"type": "spelling"
},
"generated": {
"type": "generated"
},
"merge-conflict": {
"type": "merge-conflict"
@zengyun-hacker
zengyun-hacker / gist:2c0eb3515f2ebf850e22
Created October 16, 2015 08:39 — forked from snikch/gist:3661188
Find the current top view controller for your iOS application
- (UIViewController *)topViewController{
return [self topViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}
- (UIViewController *)topViewController:(UIViewController *)rootViewController
{
if (rootViewController.presentedViewController == nil) {
return rootViewController;
}
@zengyun-hacker
zengyun-hacker / gist:7336bddb8a18937f80ba
Created February 7, 2015 09:40
how to get file name when saving a image
UIImage *image; //The image would be save
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)image.imageOrientation completionBlock:^(NSURL *assetURL, NSError *error) {
if (!error) {
[library assetForURL:assetURL resultBlock:^(ALAsset *asset) {
ALAssetRepresentation *defaultRep = [asset defaultRepresentation];
NSString *fileName = [defaultRep filename];
} failureBlock:^(NSError *error) {
}];
}
@zengyun-hacker
zengyun-hacker / 不分心系列
Last active August 29, 2015 14:07
让你认真工作学习不会分心的hosts列表
127.0.0.1 t.sina.com.cn
127.0.0.1 weibo.com
127.0.0.1 zhihu.com
127.0.0.1 douban.com
127.0.0.1 cnbeta.com
127.0.0.1 renren.com
127.0.0.1 xiaonei.com
127.0.0.1 zhibo8.cc
127.0.0.1 zhibo8.com
127.0.0.1 36kr.com
@zengyun-hacker
zengyun-hacker / screenshot
Created May 12, 2014 05:53
make a screenshot and save it into UIImage
UIWindow *window = [UIApplication sharedApplication].keyWindow;
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
UIGraphicsBeginImageContextWithOptions(window.bounds.size, NO, [UIScreen mainScreen].scale);
}
else {
UIGraphicsBeginImageContext(window.bounds.size);
}
if ([window respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]) {
[window drawViewHierarchyInRect:window.bounds afterScreenUpdates:YES];
}
@zengyun-hacker
zengyun-hacker / draw line
Created October 7, 2013 03:32
draw line
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
// Draw them with a 2.0 stroke width so they are a bit more visible.
CGContextSetLineWidth(context, 2.0);
CGContextMoveToPoint(context, 0,0); //start at this point
/*
* attention: before this you should have a AVAudioPlayerDelegate
*/
//init
NSString *audioPath = [[NSBundle mainBundle]pathForResource:@"audio" ofType:@"mp3"];
NSURL *audioURL = [NSURL fileURLWithPath:audioPath];
NSError *error;
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:audioURL error:&error];
if (error) {
@zengyun-hacker
zengyun-hacker / set navigation bar background image
Last active December 23, 2015 17:19
set navigation bar background image
//call this in didFinishLaunchingWithOptions of appdelegate
[[UINavigationBar appearance] setBackgroundImage:#background image# forBarMetrics:UIBarMetricsDefault];
@zengyun-hacker
zengyun-hacker / ios macro
Created September 23, 2013 08:55
common macro in iOS
#pragma mark - Log
//debug log
#ifdef DEBUG
# define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
# define DLogRect(rect) DLog(@"%s x=%f, y=%f, w=%f, h=%f", #rect, rect.origin.x, rect.origin.y,rect.size.width, rect.size.height)
# define DLogPoint(pt) DLog(@"%s x=%f, y=%f", #pt, pt.x, pt.y)
# define DLogSize(size) DLog(@"%s w=%f, h=%f", #size, size.width, size.height)
# define DLogColor(_COLOR) DLog(@"%s h=%f, s=%f, v=%f", #_COLOR, _COLOR.hue, _COLOR.saturation, _COLOR.value)
@zengyun-hacker
zengyun-hacker / Customize title view of navigation bar
Created September 23, 2013 08:54
Customize title view of navigation bar
#define FONT(x) [UIFont systemFontOfSize:x]
#define LOADIMAGE(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]]
//set text title
- (void)setNavigationTitle:(NSString *)title{
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.text = title;
titleLabel.font = FONT(13);
titleLabel.textColor = [UIColor whiteColor];
self.navigationItem.titleView = titleLabel;