xcode - 将 UIImageView 的形状或大小更改为标准,以在 tableview 中圆形

标签 xcode swift uitableview

如何将表格 View 中的 UIImageView 的大小更改为圆形? 下面的代码片段取自表格 View 数据源。

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
    let myCell = tableView.dequeueReusableCellWithIdentifier("myCell", forIndexPath: indexPath) as UITableViewCell
        switch(mySegmentedControl.selectedSegmentIndex)
        {
        case 0 :
                myCell.textLabel?.text = aaa[indexPath.row] as? String
                myCell.imageView?.image = images[indexPath.row]
            break
        case 1 :
            myCell.textLabel?.text = bbb[indexPath.row] as? String
                myCell.imageView?.image = nil
            break
        case 2 :
            myCell.textLabel?.text =  cccc[indexPath.row] as? String
                myCell.imageView?.image = nil
            break
        default:
            break
        }
    return myCell
    }

最佳答案

您可能看到的是改变 UIImageView 的形状,而不是 UIImage 本身。最简单的方法是向图层添加蒙版:

let layer = myCell.imageView?.layer
layer.cornerRadius = layer.frame.size.height/2
layer.masksToBounds = true

关于xcode - 将 UIImageView 的形状或大小更改为标准,以在 tableview 中圆形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33709452/

相关文章:

objective-c - iOS 7.1 imagePicker CameraFlashMode 不指示开/关状态

ios - 解析登录不起作用(快速)

ios - 为什么我的 UITableView 没有完全加载单元格内容?

ios - 如何在 Swift 中进行弱链接?

uitableview - 在 Swift 中为 cellForRowAtIndexPath 调用 super

iphone - UITableViewCell 中的 UITextField

ios - Xcode 7 : Where is "Log Navigator", 而不是 "Report Navigator"?

ios - 每次进行更改时预览都会出错 (SwiftUI)

iphone - 在 Objective-C 和 iOS 中合并项目范围定义的最佳实践

ios - 停止 NSURLRequest 写入缓存