在iOS中设置CALayer的“ borderWidth”和“ cornerRadius”,不能完全覆盖背景 [英] Set the CALayer 'borderWidth' and 'cornerRadius' in iOS, can not fully covers background

查看:369
本文介绍了在iOS中设置CALayer的“ borderWidth”和“ cornerRadius”,不能完全覆盖背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    self.yuanjiao.backgroundColor = [UIColor blackColor];
    self.yuanjiao.layer.cornerRadius = self.yuanjiao.frame.size.width/2;
    self.yuanjiao.layer.masksToBounds = YES;
    self.yuanjiao.layer.borderWidth = 5;
    self.yuanjiao.layer.borderColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1].CGColor;

    //    self.yuanjiao.layer.shadowOffset = CGSizeMake(0, 0);
    //    self.yuanjiao.layer.shadowRadius = 0.0;
    //    self.yuanjiao.layer.shadowColor = [UIColor whiteColor].CGColor;
    //    self.yuanjiao.layer.shadowOpacity = 0.0;
}

效果:

边界没有完全覆盖背景。

Border not fully cover the the background.

设置shadowxxx无效。

Setting shadowxxx has no effect.

推荐答案

这是图层属性的预期行为。如果您查看 Apple文档 borderWidth 属性,您将找到:-

This is the intended behaviour of layer's property. If you look at Apple Documentation for borderWidth property, you will find: -


讨论

此值大于0.0时,图层将使用当前的borderColor值绘制边框。边框是根据此属性中指定的值从接收者的边界绘制的。 它在接收者的内容和子层之上进行了合成,并包含cornerRadius属性的效果。

此属性的默认值为0.0。 / p>

The default value of this property is 0.0.

如果您需要用<$ c $填充 borderWidth 部分c> blackColor ,那么您有两个选择

If you are in need to fill the borderWidth portion with blackColor as well, then you have two choices


  1. 边框颜色没有意义与视图的内容没有什么不同。您将完全看不到边框。您将看到的是一个更大的圆圈,里面充满了 blackColor

  2. 如果您想保留边框并且还需要用黑色填充颜色,然后将 borderColor 属性分配给 blackColor

  1. There is no point in having a border whose color is not different than the content of view. You will not be able to see the border at all. All you will see is a little bigger circle filled with blackColor.
  2. If you wanna keep border and also needs to fill it with black color then assign the borderColor property to blackColor.

这篇关于在iOS中设置CALayer的“ borderWidth”和“ cornerRadius”,不能完全覆盖背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆