Created
February 9, 2020 22:30
-
-
Save vinczebalazs/83743f05ba028500c733be7830e23dda to your computer and use it in GitHub Desktop.
A Playground to reproduce a cornerRadius anomality.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: A UIKit based Playground for presenting user interface | |
import UIKit | |
import PlaygroundSupport | |
final class Cell: UITableViewCell { | |
private let borderLayer = CAShapeLayer() | |
private let _backgroundView = UIView() | |
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { | |
super.init(style: style, reuseIdentifier: reuseIdentifier) | |
// Add a blue background view. | |
contentView.insertSubview(_backgroundView, at: 0) | |
_backgroundView.backgroundColor = .blue | |
_backgroundView.layer.cornerRadius = 28 | |
// Add the border layer. | |
borderLayer.fillColor = nil | |
borderLayer.strokeColor = UIColor.red.cgColor | |
borderLayer.lineWidth = 2 | |
contentView.layer.addSublayer(borderLayer) | |
} | |
override func layoutSubviews() { | |
super.layoutSubviews() | |
_backgroundView.frame = contentView.bounds | |
borderLayer.path = UIBezierPath(roundedRect: contentView.bounds, cornerRadius: _backgroundView.layer.cornerRadius).cgPath | |
} | |
required init?(coder: NSCoder) { | |
super.init(coder: coder) | |
} | |
} | |
class MyViewController : UITableViewController { | |
let testView = UIView(frame: CGRect(x: 100, y: 100, width: 200, height: 100)) | |
override func loadView() { | |
let tableView = UITableView() | |
tableView.dataSource = self | |
tableView.rowHeight = 84 | |
tableView.register(Cell.self, forCellReuseIdentifier: "Cell") | |
tableView.separatorStyle = .none | |
self.tableView = tableView | |
} | |
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
1 | |
} | |
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) | |
} | |
} | |
// Present the view controller in the Live View window | |
PlaygroundPage.current.liveView = MyViewController() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment