ios - uitableViewCell.rounded 角不会立即显示
<p><p>我有这些collectionViewCell的方法</p>
<pre><code>cell.restarauntImage.roundCorners([.TopLeft, .TopRight], radius: 10, borderColor: UIColor.clearColor(), borderWidth: 0)
</code></pre>
<p>和tableViewCell </p>
<pre><code>cell.restImage.roundCorners([.TopLeft, .TopRight], radius: 7, borderColor: UIColor.clearColor(), borderWidth: 0)
</code></pre>
<p>问题在于它与collectionView完美配合,但在tableView中它不能立即与.TopRight一起工作,它仅适用于我多次重复使用单元格,但是.TopLeft有效。此外,如果我删除 .TopLeft 并尝试仅应用于 .TopRight 它也不起作用。可能是什么问题?</p>
<p>更新:在堆栈溢出时发现扩展</p>
<pre><code>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)
}
}
</code></pre>
<p>update2: cellForRowAtIndexPath,我尝试在ink_setImage之后将此方法应用于每个案例,但它也不起作用。</p>
<pre><code>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
}
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>尝试将 <code>self.tableView.reloadData()</code> 调用放在 <code>viewDidLoad</code> 方法的末尾,这可能会解决延迟问题。</p></p>
<p style="font-size: 20px;">关于ios - uitableViewCell.rounded 角不会立即显示,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/38720729/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/38720729/
</a>
</p>
页:
[1]