iOS中的透明环

iOS中的透明环,ios,objective-c,uiimageview,uikit,core-graphics,Ios,Objective C,Uiimageview,Uikit,Core Graphics,我的视野中有一个圆形的化身。我是这样做的: self.imageView.layer.cornerRadius = 75; self.imageView.layer.masksToBounds = YES; self.imageView.layer.borderWidth = 1; self.imageView.layer.borderColor = [UIColor whiteColor].CGColor; 但我想在阿凡达和白色边框之间有一个透明的2px戒指。我不能在背景上画一个白色的圆圈,

我的视野中有一个圆形的化身。我是这样做的:

self.imageView.layer.cornerRadius = 75;
self.imageView.layer.masksToBounds = YES;
self.imageView.layer.borderWidth = 1;
self.imageView.layer.borderColor = [UIColor whiteColor].CGColor;
但我想在阿凡达和白色边框之间有一个透明的2px戒指。我不能在背景上画一个白色的圆圈,因为化身可以移动,戒指的位置会丢失。我的想法是使用

CGContextSetBlendMode(context, kCGBlendModeClear);

在指定图层后,但我不知道如何准确地执行它。感谢您的帮助。

那个问题似乎只是缺乏想象力的问题

以下是该问题的快速解决方案: 在界面生成器中,您需要添加一个容器视图,该视图保存化身图像视图;这是它在我的屏幕上显示的原始图片编辑器中的视图:

这是视图层次结构中两个视图之间的关系:容器视图是化身图像视图的超级视图:

添加相关出口后,将其称为类的_containerView和_avatarImageView,并将其连接到视图;我们还可以在代码中添加以下小片段:

[_containerView setBackgroundColor:[UIColor clearColor]];
[_containerView.layer setCornerRadius:MIN(_containerView.bounds.size.width, _containerView.bounds.size.height) / 2.0];
[_containerView.layer setBorderColor:[[UIColor whiteColor] CGColor]];
[_containerView.layer setBorderWidth:4.0];

[_avatarImageView.layer setCornerRadius:MIN(_avatarImageView.bounds.size.width, _avatarImageView.bounds.size.height) / 2.0];
[_avatarImageView.layer setMasksToBounds:TRUE];
在模拟器或真实设备violá上运行项目后,透明环出现在图像和边界之间:


注意:透明环的实际大小取决于化身比容纳它的容器视图小多少。重要的我不知道那个女孩是谁,请不要问我她的电话号码。

那个问题似乎只是缺乏想象力的问题

以下是该问题的快速解决方案: 在界面生成器中,您需要添加一个容器视图,该视图保存化身图像视图;这是它在我的屏幕上显示的原始图片编辑器中的视图:

这是视图层次结构中两个视图之间的关系:容器视图是化身图像视图的超级视图:

添加相关出口后,将其称为类的_containerView和_avatarImageView,并将其连接到视图;我们还可以在代码中添加以下小片段:

[_containerView setBackgroundColor:[UIColor clearColor]];
[_containerView.layer setCornerRadius:MIN(_containerView.bounds.size.width, _containerView.bounds.size.height) / 2.0];
[_containerView.layer setBorderColor:[[UIColor whiteColor] CGColor]];
[_containerView.layer setBorderWidth:4.0];

[_avatarImageView.layer setCornerRadius:MIN(_avatarImageView.bounds.size.width, _avatarImageView.bounds.size.height) / 2.0];
[_avatarImageView.layer setMasksToBounds:TRUE];
在模拟器或真实设备violá上运行项目后,透明环出现在图像和边界之间:


注意:透明环的实际大小取决于化身比容纳它的容器视图小多少。重要的我不知道那个女孩是谁,请不要问我她的电话号码。

是的,谢谢你的快速回复和轻量级解决方案!是的,感谢您的快速回复和轻量级解决方案!