顯示我的這些方法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
}
}
什麼是您的roundCorners方法是什麼樣子?這不是由UIKit提供的方法... – Arclite
添加擴展代碼主題 – JuicyFruit
我們展示的cellForRowAtIndexPath方法請 –