iOS(CoreGraphics)画带箭头的框

自己画带箭头的框,需要导入CoreGraphics.framwork库

新建一个集成UIView 的类,对UIView中的drawRect:(CGRect)rect方法重写如下。


绘图操作

//绘制带箭头的矩形

-(void)drawArrowRectangle:(CGRect) frame

{

    // 获取当前图形,视图推入堆栈的图形,相当于你所要绘制图形的图纸

    CGContextRef ctx =UIGraphicsGetCurrentContext();

    // 创建一个新的空图形路径。

    CGContextBeginPath(ctx);

    //启始位置坐标xy

    CGFloat origin_x = frame.origin.x;

    CGFloat origin_y = frame.origin.y;

    //第一条线的位置坐标

    CGFloat line_1_x = frame.size.width;

    CGFloat line_1_y = origin_y;

    //第二条线的位置坐标

    CGFloat line_2_x = line_1_x;

    CGFloat line_2_y = frame.size.height;

    //第三条线的位置坐标

    CGFloat line_3_x = origin_x + 20;

    CGFloat line_3_y = line_2_y;

    //尖角的顶点位置坐标

    CGFloat line_4_x = line_3_x - 5;

    CGFloat line_4_y = line_2_y + 10;

    //第五条线位置坐标

    CGFloat line_5_x = line_4_x - 5;

    CGFloat line_5_y = line_3_y;

    //第六条线位置坐标

    CGFloat line_6_x = origin_x;

    CGFloat line_6_y = line_2_y;

    

    CGContextMoveToPoint(ctx, origin_x, origin_y);

    

    CGContextAddLineToPoint(ctx, line_1_x, line_1_y);

    CGContextAddLineToPoint(ctx, line_2_x, line_2_y);

    CGContextAddLineToPoint(ctx, line_3_x, line_3_y);

    CGContextAddLineToPoint(ctx, line_4_x, line_4_y);

    CGContextAddLineToPoint(ctx, line_5_x, line_5_y);

    CGContextAddLineToPoint(ctx, line_6_x, line_6_y);

    

    CGContextClosePath(ctx);

    

    UIColor *costomColor = [UIColorcolorWithWhite:0alpha:0.8];

    CGContextSetFillColorWithColor(ctx, costomColor.CGColor);

    

    CGContextFillPath(ctx);


}


//重写绘图,调用刚才绘图的方法

-(void)drawRect:(CGRect)rect

{

    CGRect frame = rect;

    frame.size.height = frame.size.height -20;

    rect = frame;

    //绘制带箭头的框框

    [selfdrawArrowRectangle:rect];

}


效果如下图:(带箭头的框中的信息是后添加的,这里只是介绍了利用CoreGraphics画图)



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值