美文网首页
ios ~ 设置UIView的外边框

ios ~ 设置UIView的外边框

作者: 阳光下的叶子呵 | 来源:发表于2021-12-30 16:59 被阅读0次
    一般设置内边框:
        self.headImg.layer.borderColor = [UIColor redColor].CGColor;
        self.headImg.layer.borderWidth = [UIScreen mainScreen].bounds.size.width/375*2;
    
    而设置外边框:(注意:backView 是headImg的父视图,这个layer是沿着headImg边框路径,添加到backView的layer)
            CGFloat borderWidth = [UIScreen mainScreen].bounds.size.width/375*2;
            CALayer *layer = [CALayer layer];
            layer.frame = CGRectMake(self.headImg.frame.origin.x - borderWidth, self.headImg.frame.origin.y - borderWidth, self.headImg.frame.size.width + 2 * borderWidth, self.headImg.frame.size.height + 2 * borderWidth);
            
            layer.masksToBounds = YES;
            layer.cornerRadius = [UIScreen mainScreen].bounds.size.width/375*(50 + 2 * borderWidth)/2;
    //        layer.borderColor = RGBA(255, 196, 15, 0.3).CGColor;
            layer.borderColor = [UIColor redColor].CGColor;
            layer.borderWidth = [UIScreen mainScreen].bounds.size.width/375*2;
            [self.backView.layer addSublayer:layer];
         
    
    

    相关文章

      网友评论

          本文标题:ios ~ 设置UIView的外边框

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