如何将表格 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/