带边框的圆形UIImageView - 原始边缘

时间:2015-03-22 13:12:21

标签: ios uiimageview core-graphics

我正试图获得顺利的角落,但没有成功。 这是它的外观:

enter image description here

我有UIImageView的子类,在layoutSubviews中我有为uiimageview设置圆角的逻辑,并且它被剪切到边界。

但我不明白为什么有些图像是用这些原始边缘绘制的,而且它们是边界层之外的......

因为它被剪裁了,所以我无法为边框创建一个具有不同框架的自定义图层,因为剪切了整个超层。

- (void)layoutSubviews
    {
        [super layoutSubviews];
        [self layoutIfNeeded];
        [self.layer setCornerRadius:self.frame.size.width/2];
        [self.layer setBorderWidth:BORDERSIZE];
        [self.layer setBorderColor:[BORDERCOLOR CGColor]];
        [self setClipsToBounds:YES];

    }

1 个答案:

答案 0 :(得分:-1)

要使圆形图像视图在viewDidLoad中使用以下代码。对于clipped to bounds,将其设置为yes。

self.MyImageView.layer.cornerRadius = self.MyImageView.frame.size.width / 2;
self.MyImageView.clipsToBounds = YES;

要应用边框,请在viewDidLoad中使用此代码:

self.MyImageView.layer.borderWidth = 3.0f;
self.MyImageView.layer.borderColor = [UIColor whiteColor].CGColor;

这肯定会有效。

相关问题