使UIImage clipsToBound通过UITableViewCell

我有一个UITableViewController与静态表格单元格。使UIImage clipsToBound通过UITableViewCell

而我试图用这个单元格UIImageView和这个图像clipToBounds,但它不工作。

这是我想要做的一个示例。

但是当我做一个UITableView并设置UIImage的clipToBounds到TRUE

结果是:

我只是需要一种方法来使UIImageView喜欢第一个图像无论如何与UITableView单元格?

,这是我的UIImageView约束:

,这里是我的代码:

class ProfileTableViewController: UITableViewController { 

@IBOutlet weak var userImage: UIImageView!

override func viewDidLoad() {

super.viewDidLoad()

// Uncomment the following line to preserve selection between presentations

// self.clearsSelectionOnViewWillAppear = false

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.

// self.navigationItem.rightBarButtonItem = self.editButtonItem()

// image view

self.userImage.layer.cornerRadius = self.userImage.frame.width/2

self.userImage.clipsToBounds = true

}

// MARK: - 表视图的数据源

override func numberOfSections(in tableView: UITableView) -> Int { 

// #warning Incomplete implementation, return the number of sections

return 3

}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

// #warning Incomplete implementation, return the number of rows

var number = 0

if section == 0

{

number = 1

}else if section == 1

{

number = 4

}else if section == 2

{

number = 1

}

return number

}

override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {

return 100

}

}

回答:

我找到了解决办法,当我加入此方法,并添加自定义区段标题

,并给它clipToBounds =假

问题解决了

我刚刚加入:

override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { 

let view = UIView()

view.clipsToBounds = false

return view

}

,它的工作完美:))

感谢所有试图帮助我

回答:

为什么clipsToBounds = true ? 如果图像必须outside细胞,那么我想你想的正好相反:

yourView.clipsToBounds = false 

回答:

刚刚创建图像视图插座让拐角半径itswidth/2(确保高度和宽度相同的大小),并夹界定为真。例如:

imageView = imageView.frame.size.width/2; 

imageView.clipsToBounds = true;

回答:

这可能会解决您的问题。在indexPath

细胞用于行

let height = CGFloat(cell.frame.size.height-10) 

let leading = (cell.frame.size.width - height)/2

let top = CGFloat(18)

let myImage = UIImageView(frame: CGRect(x: leading, y: top, width: height, height:height))

myImage.layer.masksToBounds = true

myImage.layer.cornerRadius = (height)/2

cell.contentView.addSubview(myImage)

// OR

cell.myImage.layer.cornerRadius = cell.myImage.frame.width/2 

cell.myImage.clipsToBounds = true

回答:

尝试这样

enter image description here

以上是 使UIImage clipsToBound通过UITableViewCell 的全部内容, 来源链接: utcz.com/qa/262711.html

回到顶部