Xcode 将UIImageView的标准形状或大小更改为tableview中的圆形

Xcode 将UIImageView的标准形状或大小更改为tableview中的圆形,xcode,swift,uitableview,Xcode,Swift,Uitableview,如何将表格视图中UIImageView的大小更改为圆形? 下面的代码段取自表视图数据源 func tableViewtableView:UITableView,cellForRowAtIndexPath索引XPath:NSIndexPath->UITableViewCell { 让myCell=tableView.dequeueReusableCellWithIdentifiermyCell,forIndexPath:indexPath作为UITableViewCell switchmySeg

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

func tableViewtableView:UITableView,cellForRowAtIndexPath索引XPath:NSIndexPath->UITableViewCell { 让myCell=tableView.dequeueReusableCellWithIdentifiermyCell,forIndexPath:indexPath作为UITableViewCell switchmySegmentedControl.selectedSegmentIndex { 案例0: myCell.textlab?.text=aaa[indexPath.row]作为?字符串 myCell.imageView?.image=images[indexPath.row] 打破 案例1: myCell.textlab?.text=bbb[indexPath.row]作为?字符串 myCell.imageView?.image=nil 打破 案例2: myCell.textlab?.text=cccc[indexPath.row]作为?字符串 myCell.imageView?.image=nil 打破 违约: 打破 } 返回迈塞尔
} 您可能看到的是更改UIImageView的形状,而不是UIImage本身。最简单的方法是向图层添加遮罩:

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

我仍然有同样的问题,有些图像比其他图像大,你的图像大小相同吗?是否在任何位置修改图像视图的边框或边界?否图像的大小不同。不,我不会在任何地方修改图像单元格的边界,你要做的就是拉伸图像。好吧,这看起来不太好,但下面是如何做到的: