我怎样才能在我的自定义 table 视图单元格上实现此 UI
how can i achive this UI on my custom table view cell
我想在我的 uitableviewcell 上实现这个自定义形状,我该怎么做?
UITableViewCell
对圆弧使用UIBezierPath
。
将此 class 添加到您的视图中。
class CellShapeView: UIView {
var fillColor: UIColor = .yellow
private var path: UIBezierPath = UIBezierPath()
override func awakeFromNib() {
super.awakeFromNib()
self.backgroundColor = UIColor.clear
}
override func draw(_ rect: CGRect) {
super.draw(rect)
//For Round corners
UIBezierPath(roundedRect: rect, byRoundingCorners: .allCorners, cornerRadii: CGSize(width: 10, height: 10)).addClip()
path.move(to: CGPoint(x: 0, y: self.frame.size.height))
path.addLine(to: CGPoint(x: 0, y: 0))
path.addLine(to: CGPoint(x: self.frame.size.width, y: 0))
path.addLine(to: CGPoint(x: self.frame.size.width, y: self.frame.size.height))
path.move(to: CGPoint(x: self.frame.size.width, y: self.frame.size.height))
//Right Side circle arc
path.addArc(withCenter: CGPoint(x: self.frame.size.width, y: self.frame.size.height/2),
radius: 10,
startAngle: CGFloat((270 * Double.pi) / 180),
endAngle: CGFloat((90 * Double.pi) / 180),
clockwise: false)
path.close()
fillColor.setFill()
path.fill()
}
}
我想在我的 uitableviewcell 上实现这个自定义形状,我该怎么做?
UITableViewCell
对圆弧使用UIBezierPath
。
将此 class 添加到您的视图中。
class CellShapeView: UIView {
var fillColor: UIColor = .yellow
private var path: UIBezierPath = UIBezierPath()
override func awakeFromNib() {
super.awakeFromNib()
self.backgroundColor = UIColor.clear
}
override func draw(_ rect: CGRect) {
super.draw(rect)
//For Round corners
UIBezierPath(roundedRect: rect, byRoundingCorners: .allCorners, cornerRadii: CGSize(width: 10, height: 10)).addClip()
path.move(to: CGPoint(x: 0, y: self.frame.size.height))
path.addLine(to: CGPoint(x: 0, y: 0))
path.addLine(to: CGPoint(x: self.frame.size.width, y: 0))
path.addLine(to: CGPoint(x: self.frame.size.width, y: self.frame.size.height))
path.move(to: CGPoint(x: self.frame.size.width, y: self.frame.size.height))
//Right Side circle arc
path.addArc(withCenter: CGPoint(x: self.frame.size.width, y: self.frame.size.height/2),
radius: 10,
startAngle: CGFloat((270 * Double.pi) / 180),
endAngle: CGFloat((90 * Double.pi) / 180),
clockwise: false)
path.close()
fillColor.setFill()
path.fill()
}
}