Ich habe für collectionViewCelltableViewCell.roundCorners nicht sofort
cell.restarauntImage.roundCorners([.TopLeft, .TopRight], radius: 10, borderColor: UIColor.clearColor(), borderWidth: 0)
und tableViewCell diese Methoden gezeigt
cell.restImage.roundCorners([.TopLeft, .TopRight], radius: 7, borderColor: UIColor.clearColor(), borderWidth: 0)
das Problem ist, dass es perfekt mit Collection funktioniert, aber in Tableview ist es nicht sofort funktioniert mit .TopRight, gilt es nur, wenn ich Zelle mehrmals wiederverwende. TopLeft funktioniert. Auch wenn ich .TopLeft entferne und versuche, nur auf .TopRight anzuwenden, funktioniert es auch nicht. Was könnte das Problem sein?
Update: Erweiterung gefunden auf Stack-Überlauf
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, habe ich versucht, nach ink_setImage dieser Methode auf jeden Fall zu bringen, aber es hat nicht funktioniert.
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
}
}
Wie sieht Ihre roundCorners-Methode aus? Dies ist keine Methode von UIKit ... – Arclite
hinzugefügt Erweiterungscode zum Thema – JuicyFruit
zeigen Sie uns cellforrowatindexpath Methode bitte –