tableViewCell.roundCorners不会立即
显示我的这些方法collectionViewCelltableViewCell.roundCorners不会立即
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
}
}
所以最终我只是说在这样dispatch_async这个功能和它的作品
dispatch_async(dispatch_get_main_queue(),{
self.content.layer.borderWidth = 1
self.content.layer.borderColor = UIColor(red: 235/255, green: 235/255, blue: 235/255, alpha: 1).CGColor
self.restarauntImage.roundCorners([.TopLeft, .TopRight], radius: 6, borderColor: UIColor.clearColor(), borderWidth: 0)
self.content.roundCorners([.BottomLeft, .BottomRight], radius: 6, borderColor: UIColor(red: 235/255, green: 235/255, blue: 235/255, alpha: 1), borderWidth: 1)})
}
如果您动态更改单元格中的视图数,还有什么更多(例如底部一个可以隐藏),你必须在你的cellForIndexPath添加几行代码,以使可重复使用的细胞正确绘制边框
cell.bottomDataView.hidden = false //show elements you have hidden
cell.backgroundGray.layer.mask = nil //delete previous mask
if cell.bottomDataView.layer.sublayers?.count > 2 {
cell.bottomDataView.layer.sublayers?.removeLast() //delete previous layer
}
你的实现似乎太复杂了,只是将一个角半径设置为imageView。 所有你需要做的是:
imageView.layer.cornerRadius = <the radius>
有时候,你可能需要申请:
imageView.clipToBounds = true
我只需要对顶部边角2设置此半径,不是所有的4 – JuicyFruit
得到它了。你试过clipToBounds = true吗?它可能会帮助 – Lirik
yeap,我做了我的形象和我的看法,没有帮助。 – JuicyFruit
什么是您的roundCorners方法是什么样子?这不是由UIKit提供的方法... – Arclite
添加扩展代码主题 – JuicyFruit
我们展示的cellForRowAtIndexPath方法请 –