Last active
November 1, 2016 02:28
-
-
Save fireblue/5027217 to your computer and use it in GitHub Desktop.
Revisions
-
fireblue revised this gist
Mar 20, 2013 . No changes.There are no files selected for viewing
-
fireblue revised this gist
Mar 20, 2013 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ -(UIImage *)screenShot { CGRect originalFrame = self.frame; -
fireblue revised this gist
Mar 20, 2013 . 1 changed file with 40 additions and 39 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,45 +1,46 @@ -(UIImage *)screenShot { CGRect originalFrame = self.frame; CGPoint originalOffset = self.scrollView.contentOffset; CGSize entireSize = [self sizeThatFits:CGSizeZero]; [self setFrame: CGRectMake(0, 0, entireSize.width, entireSize.height)]; CGRect rect = [self positionOfElementWithId:@"post1"]; //如果没有找到这个元素,就取整个页面 if (rect.origin.y != 0) { entireSize.height = rect.origin.y; } entireSize.height += 40; //第三个参数为0就是取系统默认的scale,支持retina。网上带if的只是兼容3.X以下的系统。 UIGraphicsBeginImageContextWithOptions(entireSize, NO, 0); CGContextRef context = UIGraphicsGetCurrentContext(); [self.layer renderInContext:context]; //多出来的部分画个白色背景色以放置我们尾部的文字 CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0); CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0); CGContextFillRect(context, CGRectMake(0, entireSize.height-30, entireSize.width, 30)); CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1.0); CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 1.0); NSString *contentString = @“这里是你需要加上的文字 UIFont *font = [UIFont systemFontOfSize:12]; [contentString drawInRect:CGRectMake(12, entireSize.height-27, entireSize.width, 25) withFont:font lineBreakMode:UILineBreakModeWordWrap]; UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [self setFrame:originalFrame]; self.scrollView.contentOffset = originalOffset; return screenshot; } - (CGRect)positionOfElementWithId:(NSString *)elementID { NSString *js = @"function f(){ var r = document.getElementById('%@').getBoundingClientRect(); return '{{'+r.left+','+r.top+'},{'+r.width+','+r.height+'}}'; } f();"; NSString *result = [self stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:js, elementID]]; CGRect rect = CGRectFromString(result); return rect; } -
fireblue revised this gist
Feb 25, 2013 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -38,8 +38,8 @@ -(UIImage *)screenShot } - (CGRect)positionOfElementWithId:(NSString *)elementID { NSString *js = @"function f(){ var r = document.getElementById('%@').getBoundingClientRect(); return '{{'+r.left+','+r.top+'},{'+r.width+','+r.height+'}}'; } f();"; NSString *result = [self stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:js, elementID]]; CGRect rect = CGRectFromString(result); return rect; } -
fireblue renamed this gist
Feb 25, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
fireblue created this gist
Feb 25, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ -(UIImage *)screenShot { CGRect originalFrame = self.frame; CGPoint originalOffset = self.scrollView.contentOffset; CGSize entireSize = [self sizeThatFits:CGSizeZero]; [self setFrame: CGRectMake(0, 0, entireSize.width, entireSize.height)]; CGRect rect = [self positionOfElementWithId:@"post1"]; //如果没有找到这个元素,就取整个页面 if (rect.origin.y != 0) { entireSize.height = rect.origin.y; } entireSize.height += 40; //第三个参数为0就是取系统默认的scale,支持retina。网上带if的只是兼容3.X以下的系统。 UIGraphicsBeginImageContextWithOptions(entireSize, NO, 0); CGContextRef context = UIGraphicsGetCurrentContext(); [self.layer renderInContext:context]; //多出来的部分画个白色背景色以放置我们尾部的文字 CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0); CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0); CGContextFillRect(context, CGRectMake(0, entireSize.height-30, entireSize.width, 30)); CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1.0); CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 1.0); NSString *contentString = @“这里是你需要加上的文字 UIFont *font = [UIFont systemFontOfSize:12]; [contentString drawInRect:CGRectMake(12, entireSize.height-27, entireSize.width, 25) withFont:font lineBreakMode:UILineBreakModeWordWrap]; UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [self setFrame:originalFrame]; self.scrollView.contentOffset = originalOffset; return screenshot; } - (CGRect)positionOfElementWithId:(NSString *)elementID { NSString *js = @"function f(){ var r = document.getElementById('%@').getBoundingClientRect(); return '{{'+r.left+','+r.top+'},{'+r.width+','+r.height+'}}'; } f();"; NSString *result = [self stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:js, elementID]]; CGRect rect = CGRectFromString(result); return rect; }