`

UIGraphicsGetCurrentContext

 
阅读更多

CGContextRef context = UIGraphicsGetCurrentContext(); 设置绘图的上下文,

函数UIGraphicsGetCurrentContext一般在UIView的drawRect里调用。

 

 

- (void) drawRect:(CGRect)rect
{
    CGContextRef    context = UIGraphicsGetCurrentContext();
    CGRect          myFrame = self.bounds;
    CGContextSetLineWidth(context, 2.0);
    CGRectInset(myFrame, 5, 5);
    [[UIColor redColor] setStroke];
    [[UIColor blueColor] setFill];
    UIRectFrame(myFrame);
}

 

 

Quart 2D  CGContextRef :  http://blog.sina.com.cn/s/blog_7ff0f30f01011hk9.html 

分享到:
评论

相关推荐

    UIImageView实现触摸绘图

    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(),currentPoint.x, currentPoint.y);//终点坐标 CGContextStrokePath(UIGraphicsGetCurrentContext());//开始绘制 //将画好得生成image保存在原图片///...

    ios触摸画图生成五角星

    CGContextRef ref=UIGraphicsGetCurrentContext(); [drewImage.image drawInRect:CGRectMake(0, 0, drewImage.frame.size.width, drewImage.frame.size.height)]; CGContextSetLineCap(ref,kCGLineCapSquare); ...

    ios-鹏哥哥放大镜.zip

    // 自动调用drawRect方法,这样可以拿到 UIGraphicsGetCurrentContext,就可以画画 [self.magnifyView setNeedsDisplay]; } 在移动方法中 设置其放大点 目的让其跟随手指进行移动 (void)touchesMoved:(NSSet *)...

    自定义键盘

    CGContextRef context = UIGraphicsGetCurrentContext(); [color set]; CGContextFillRect(context, CGRectMake(0, 0, size.width, size.height)); UIImage *image = ...

    ios开发小技巧

    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; //返回一个基于当前图形上下文的图片 UIImage *aImage = UIGraphicsGetImageFromCurrentImageContext(); //移除栈顶的基于当前位图的图形上...

    iOS快速实现环形渐变进度条

    前言 进度条相信我们大家都不陌生,往往我们很多... CGContextRef ctx = UIGraphicsGetCurrentContext();//获取上下文 CGPoint center = CGPointMake(100, 100); //设置圆心位置 CGFloat radius = 90; //设置半径 CG

    BMDrawRectView:带有热插拔 drawRect 方法块的 UIView 子类 - 方便的花花公子

    BMDrawRectView概念这个极其简单... (void)updateBlockChoiceFromSegmentedController{ BMDrawRectBlock firstBlock = ^(CGRect rect) { CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextSetStrokeColorW

    CFGradientLabelDemo:实现文字渐变色的两种方法

     (一)_ 自定义label, 实现 drawRect 方法, 在该方法里面画渐变色### 思路: 1)_ 把label的文字画到context上去(画文字的作用主要是设置 layer 的mask) CGContextRef context = UIGraphicsGetCurrentContext();...

    CoreText Swift绑定-Swift开发

    在当前图形上下文保护中绘制示例线let ctx = UIGraphicsGetCurrentContext()else {return} let attributedString = NSAttributedString(string:“ abcdefgh”)ctx.draw(attributedString.line())使用字形...

    屏幕截图功能

    CGContextRef context = UIGraphicsGetCurrentContext(); [view.layer renderInContext:context]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return...

    DSCollectionView

    setNeedsDisplay会调用自动调用drawRect方法,这样可以拿到UIGraphicsGetCurrentContext,就可以画画了。而setNeedsLayout会默认调用layoutSubViews,就可以处理子视图中的一些数据。  宗上所诉,setNeedsDisplay...

    iOS开发中使用Quartz2D绘制上下文栈和矩阵的方法

    上下文栈 一、qurza2d是怎么将绘图信息和绘图的属性绘制到图形上下文中去的? 说明: ... CGContextRef ctx=UIGraphicsGetCurrentContext();  //绘图  //第一条线  CGContextMoveToPoint(ctx, 20,

    iOS基于 UILabel实现文字添加描边功能

    可以达到文字描一圈黑边的效果: 继承UILabel以后重载drawTextInRect: ... CGContextRef c = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(c, 1); CGContextSetLineJoin(c, kCGLineJoinRound); CGConte

    iOS常用小功能(获得屏幕图像、压缩图片、加边框、调整label的size)

    摘要:获得屏幕图像,label的动态size,时间戳转化为时间,RGB转化成颜色,加边框,压缩图片,textfield的... CGContextRef context = UIGraphicsGetCurrentContext(); [theView.layer renderInContext:context]; UIImage *

    IOS游戏开发之五子棋OC版

    先上效果图 – 功能展示 – 初高级棋盘切换效果 实现思路及主要代码详解 1.绘制棋盘 利用Quartz2D绘制棋盘.... - (void)drawBackground:(CGSize)size{ ... CGContextRef ctx = UIGraphicsGetCurrentContext();

    iOS利用UITableView设置全屏分隔线的3种方法总结

    前言 本文主要给大家总结了iOS用UITableView设置全屏分隔线的3种方法,一般TableView设置全屏分隔线有下面三种方法: 1.自定义cell,手动添加... CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSe

    IOS 开发之ios视频截屏的实现代码

    IOS 开发之ios视频截屏的实现代码  现在好多视频截屏软件,这里提供一个IOS 视频截屏的方法,大家可以参考下, ... [[self.window layer] renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UI

Global site tag (gtag.js) - Google Analytics