美文网首页
边框的绘制

边框的绘制

作者: 最晴天 | 来源:发表于2017-07-18 09:50 被阅读6次
屏幕快照 2017-07-18 上午9.42.44.png

如图,给视图添加这样的边框,最简单的办法就是使用图片作为背景。
此处,使用UIBezierPath来绘制。代码如下:

#pragma mark 线框部分的设置
- (void)drawRect:(CGRect)rect{
    [super drawRect:rect];
    [self setMaskLineLayer];
}

- (void)setMaskLineLayer{
    
    if (_maskLayer == nil) {
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.strokeColor = [UIColor redColor].CGColor;
        maskLayer.fillColor = self.backgroundColor.CGColor;
        [self.layer addSublayer:maskLayer];
        _maskLayer = maskLayer;
    }
    UIBezierPath *maskPath = [self lineMaskPath];
    _maskLayer.frame = self.bounds;
    _maskLayer.path = maskPath.CGPath;
}

- (UIBezierPath *)lineMaskPath{
    
    UIBezierPath *maskPath = [UIBezierPath bezierPath];
    maskPath.lineWidth = 1.0;
    [[UIColor redColor] setStroke];
    [maskPath moveToPoint:CGPointMake(-1, 0)];
    [maskPath addLineToPoint:CGPointMake(-1, HHGet_H(self)-5)];
    [maskPath addArcWithCenter:CGPointMake(4, HHGet_H(self)-4) radius:5 startAngle:M_PI endAngle:M_PI_2 clockwise:NO];
    [maskPath addLineToPoint:CGPointMake(HHGet_W(self)-4, HHGet_H(self)+1)];
    [maskPath addArcWithCenter:CGPointMake(HHGet_W(self)-4, HHGet_H(self)-4) radius:5 startAngle:M_PI_2 endAngle:0 clockwise:NO];
    [maskPath addLineToPoint:CGPointMake(HHGet_W(self)+1, 0)];
    [maskPath stroke];

    return maskPath;
}
#pragma mark 线框部分设置结束

屏幕快照 2017-07-18 上午9.43.02.png

如图,这样的设置,可以采用为view的layer设置mask的方式

 UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, kWidthPercent*103, kRelativeHeight(30)) byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(5, 5)];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] initWithLayer:button.layer];
        maskLayer.path = maskPath.CGPath;
        maskLayer.borderWidth = 1;
        maskLayer.borderColor = HEXTOUICOLOR(@"#EE3528").CGColor;
        button.layer.mask = maskLayer;

相关文章

  • Android 日志工具包

    1). 实现效果图 2). 实现思路 绘制边框 打印线程名称 打印堆栈信息 打印消息体 3). 边框绘制 边框实际...

  • Android 圆角、圆形 ImageView 实现

    一、 特点 基于AppCompatImageView扩展 支持圆角、圆形显示 可绘制边框,圆形时可绘制内外两层边框...

  • 边框的绘制

    如图,给视图添加这样的边框,最简单的办法就是使用图片作为背景。此处,使用UIBezierPath来绘制。代码如下:...

  • Voxler对离散数据点插值成体

    导入数据,如下图:数据导入 绘制散点图,如下:绘制散点图 继续添加坐标轴及边框,如下:坐标轴及边框 网格化,如下:...

  • tableView中的section圆角

    // 重新绘制cell边框 - (void)tableView:(UITableView *)tableView ...

  • 小鱼儿学Tkinter-relief

    relief 用来控制如何绘制3D边框

  • 边框 背景

    1 边框 能够创建圆角边框,向矩形添加阴影,使用图片来绘制边框 - 并且不需使用设计软件 对于 border-im...

  • css之border

    css边框属性 通过css3,能够创建圆角边框,向矩形添加阴影,使用图片来绘制边框 border-radius b...

  • day01

    1.边框透明 2.背景的绘制区域 3.多重边框 4.双重边框 5.灵活的背景定位(background-posit...

  • UIButton 绘制边框

    button.layer.masksToBounds = YES; //允许绘制 button.layer.cor...

网友评论

      本文标题:边框的绘制

      本文链接:https://www.haomeiwen.com/subject/tauckxtx.html