ios - 创建带有圆形边框 iOS 的 UIImageView

标签 ios objective-c cocoa-touch uiimageview

我正在尝试围绕我的 UIIMageView 创建边框,这是一个使用 cornerRadius 的完美圆。我看过的所有内容都说我的代码是正确的,但它返回的更多是菱形。 (我已经导入了 quartzCore,不确定是否需要)

image.layer.cornerRadius = (image.bounds.size.width/2);
image.layer.borderWidth = 5;
image.layer.borderColor = [UIColor whiteColor].CGColor;

有什么想法吗?

最佳答案

image.layer.cornerRadius = image.frame.size.width /2;
image.layer.masksToBounds = YES;
image.layer.borderWidth = 5;
image.layer.borderColor = [UIColor whiteColor].CGColor;

imageview 的高度和宽度必须相等

关于ios - 创建带有圆形边框 iOS 的 UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31321144/

相关文章:

objective-c - 在 init 中创建后 NSMutableArray 为空(带代码)

iphone - 如何从 UIWebView 获取选择文本?

iphone - 如何创建像UITableViewCell这样的TextField?

iphone - MKMapView map 类型没有改变?

ios - 导航栏 ios 中两个 barButton 之间的间距

iPhone 类似谷歌地图应用的半透明状态栏

ios - 我的应用程序中的 PLCrashReporter 没有获取符号代码。我正在使用 PLCrashReporter 进行崩溃分析

当 UITextField 成为 Touch ID 完成 block (iOS 10) 中的第一响应者时,不显示 iOS 键盘(在 UIRemoteKeyboardWindow 内)

objective-c - 创建带有章节标记的 MP4/M4A 文件

iphone - 从 NSKeyedArchiver 加载单例状态