ios - 使图像适合圆形 ImageView

标签 ios swift image imageview

我有一个带有圆形 ImageView 的 collectionviewCell,它显示了一个图标。 不幸的是图标太大了。我怎样才能使它们适合圆形的 ImageView:

代码

func makeItCircle() {

    self.imageView.layer.cornerRadius  = self.imageView.frame.height/2
    self.imageView.layer.masksToBounds = false
    self.imageView.clipsToBounds = true
    self.imageView.contentMode = .scaleAspectFit
}

图片 enter image description here

最佳答案

您可以将 ImageView 包装在容器 View 中(您已经拥有的单元格 View 应该可以工作)以添加一些填充:将 ImageView 居中放置在其容器内并将其宽度和高度限制为容器的大约 0.75。此外,您还必须在容器上设置背景和圆角,而不是在 ImageView 上。

关于ios - 使图像适合圆形 ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46936741/

相关文章:

iphone - 如果定义了 didFinishPickingMediaWithInfo,相机会卡住

ios - 如何绘制水平条形图而不显示轴

ios - 我只想左右移动图像

swift - 如何在 Swift 中构建递归函数以返回字符串?

html - 如何使用 HTML 添加圆 Angular

ios - 将 Google 地方信息结果偏向特定区域

ios - 如何在 UITableView 中引用 UITableViewCell

ios - 当 Webview 在 Collection View 单元格中时,如何检测 UIWebView 何时开始加载?

ios - 如何在 Xcode 中对图像 Assets 使用本地化?

php - 调用未定义函数 exif_imagetype()