CGContextRef 使用小记

1. 用CGContextRef 画文字

在 UIView的 - (void)drawRect:(CGRect)rect {} 方法中进行

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetShouldAntialias(context, YES); // 抗锯齿
    CGContextSetLineWidth(context, 1.0f); //设置线宽

    /*写文字*/
        CGContextSetRGBFillColor (context,  1, 0, 0, 1.0);//设置填充颜色
        UIFont  *font = [UIFont boldSystemFontOfSize:15.0];//设置文本字体大小
        NSDictionary *attribute = @{NSFontAttributeName:wordFont,NSForegroundColorAttributeName: fontColor};
        [@"文字" drawInRect:CGRectMake(10, 20, 80, 20) withAttributes:attribute];
2. 画圆

    /** 画圆 */
    //void CGContextAddArc(CGContextRef c,CGFloat x, CGFloat y,CGFloat radius,CGFloat startAngle,CGFloat endAngle, int clockwise)1弧度=180°/π (≈57.3°) 度=弧度×180°/π 360°=360×π/180 =2π 弧度
    // x,y为圆点坐标,radius半径,startAngle为开始的弧度,endAngle为 结束的弧度,clockwise 0为顺时针,1为逆时针。

CGContextSetRGBStrokeColor(context,1,0,0,1.0);//画笔线的颜色 不设置的话是黑色

 

转载于:https://www.cnblogs.com/liuw-flexi/p/9029168.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值