我有这些collectionViewCell的方法
cell.restarauntImage.roundCorners([.TopLeft, .TopRight], radius: 10, borderColor: UIColor.clearColor(), borderWidth: 0)
和tableViewCell
cell.restImage.roundCorners([.TopLeft, .TopRight], radius: 7, borderColor: UIColor.clearColor(), borderWidth: 0)
问题在于它与collectionView完美配合,但在tableView中它不能立即与.TopRight一起工作,它仅适用于我多次重复使用单元格,但是.TopLeft有效。此外,如果我删除 .TopLeft 并尝试仅应用于 .TopRight 它也不起作用。可能是什么问题?
更新:在堆栈溢出时发现扩展
extension UIView {
func roundCorners(corners:UIRectCorner, radius: CGFloat, borderColor: UIColor, borderWidth: CGFloat)
{
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.CGPath
self.layer.mask = mask
addBorder(mask, borderWidth: borderWidth, borderColor: borderColor)
}
private func addBorder(mask: CAShapeLayer, borderWidth: CGFloat, borderColor: UIColor) {
let borderLayer = CAShapeLayer()
borderLayer.path = mask.path
borderLayer.fillColor = UIColor.clearColor().CGColor
borderLayer.strokeColor = borderColor.CGColor
borderLayer.lineWidth = borderWidth
borderLayer.frame = bounds
layer.addSublayer(borderLayer)
}
}
update2: cellForRowAtIndexPath,我尝试在ink_setImage之后将此方法应用于每个案例,但它也不起作用。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("searchCell" , forIndexPath: indexPath) as! SearchTableViewCell
cell.restImage.roundCorners([.TopLeft, .TopRight], radius: 10, borderColor: UIColor.clearColor(), borderWidth: 0)
cell.backgroundGray.roundCorners([.BottomLeft, .BottomRight], radius: 7, borderColor: UIColor.clearColor(), borderWidth: 0)
switch (indexPath.row) {
case 0:
cell.restImage.hnk_setImageFromURL(NSURL(string: "https://pp.vk.me/c636117/v636117560/29385/OukzPhoe4q0.jpg")!)
case 1:
cell.restImage.hnk_setImageFromURL(NSURL(string: "https://pp.vk.me/c636117/v636117560/29385/OukzPhoe4q0.jpg")!)
case 2:
cell.restImage.hnk_setImageFromURL(NSURL(string: "https://pp.vk.me/c636117/v636117560/29385/OukzPhoe4q0.jpg")!)
case 3:
cell.restImage.hnk_setImageFromURL(NSURL(string: "https://pp.vk.me/c636117/v636117560/29385/OukzPhoe4q0.jpg")!)
default:
cell.restImage.hnk_setImageFromURL(NSURL(string: "https://pp.vk.me/c636117/v636117560/29385/OukzPhoe4q0.jpg")!)
return cell
}
}
尝试将 self.tableView.reloadData()
调用放在 viewDidLoad
方法的末尾,这可能会解决延迟问题。
关于ios - uitableViewCell.rounded 角不会立即显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38720729/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://ogeek.cn/) | Powered by Discuz! X3.4 |