下面代码实现画圆、画弧、画扇形

//画圆

- (void)drawCircle{

    //获取上下文

    CGContextRef context = UIGraphicsGetCurrentContext();

    

    //画圆

    CGContextAddEllipseInRect(context, CGRectMake(10, 10, 100, 100));

    

    //渲染

    CGContextStrokePath(context);

    

 

}

 

//画弧

- (void)drawArc{

    //获取上下文

    CGContextRef context = UIGraphicsGetCurrentContext();

    

    /*

     * x , y 圆心

     *radius 半径

     *startangle 弧起点

     *clockwise 0 顺时针 1 :逆时针

     */

    CGContextAddArc(context, 100, 100, 41, 0, M_PI_2, 1);

    

    //渲染

    //CGContextStrokePath(context);

    CGContextFillPath(context);

}

 

//画扇形

- (void)drawSector{

    CGContextRef context = UIGraphicsGetCurrentContext();

    

    CGContextMoveToPoint(context, 100, 100);

    

    CGContextAddArc(context, 100, 100, 60, -M_PI_4, -3 * M_PI_4, 1);

    

    //封闭

    CGContextClosePath(context);

    

    CGContextStrokePath(context);

}

 

、、、、、、、、、、、、、、、、、、、、、、

画文字 和图片

不同于之前画圆之类

实现代码如下

- (void)drawRect:(CGRect)rect {

    // Drawing code

    

    CGFloat w = rect.size.width;

    CGFloat h = rect.size.height;

    

    //画图片

    UIImage *image = [UIImage imageNamed:@"papa"];

//    [image drawAtPoint:CGPointZero];

//    [image drawInRect:CGRectMake(0, 0, 50, 50)];

    

    //平铺

    [image drawAsPatternInRect:CGRectMake(0, 0, 180 , 180)];

    

    //画文字

    NSString *text = @"jhghjhfjhfkgbjhbnmbhhjtyfvhhdcbsxfsx这个交互是由两个View组成,左侧导航的View在下面,显示内容列表的View在上面,内容列表的View覆盖住了导航View,拖动内容列表的View向右,这时候导航View就显示出来了。";

    

//    //这个方法不会换行

//    [text drawAtPoint:CGPointMake(10, 100) withAttributes:nil];

    

    //设置字体样式

    NSDictionary *attr = @{NSFontAttributeName:[UIFont systemFontOfSize:13],NSForegroundColorAttributeName:[UIColor yellowColor ]};

    

    //指定宽度和高度

    [text drawInRect:CGRectMake(0, 0, w, 0.5 * h) withAttributes:attr];

    

}

posted on 2015-12-01 23:08  BansheeLw  阅读(117)  评论(0编辑  收藏  举报