round top corners

This commit is contained in:
Michael Kirk 2018-07-11 10:18:45 -06:00
parent 57400e1ecb
commit adfaeaa8e1

View file

@ -129,6 +129,8 @@ class MessageActionView: UIView {
super.init(frame: CGRect.zero) super.init(frame: CGRect.zero)
backgroundColor = .white
let imageView = UIImageView(image: action.image) let imageView = UIImageView(image: action.image)
let imageWidth: CGFloat = 24 let imageWidth: CGFloat = 24
imageView.autoSetDimensions(to: CGSize(width: imageWidth, height: imageWidth)) imageView.autoSetDimensions(to: CGSize(width: imageWidth, height: imageWidth))
@ -152,10 +154,11 @@ class MessageActionView: UIView {
contentRow.alignment = .center contentRow.alignment = .center
contentRow.spacing = 12 contentRow.spacing = 12
contentRow.isLayoutMarginsRelativeArrangement = true contentRow.isLayoutMarginsRelativeArrangement = true
contentRow.layoutMargins = UIEdgeInsets(top: 17, left: 16, bottom: 17, right: 16) contentRow.layoutMargins = UIEdgeInsets(top: 7, left: 16, bottom: 7, right: 16)
self.addSubview(contentRow) self.addSubview(contentRow)
contentRow.autoPinToSuperviewMargins() contentRow.autoPinToSuperviewMargins()
contentRow.autoSetDimension(.height, toSize: 42, relation: .greaterThanOrEqual)
} }
required init?(coder aDecoder: NSCoder) { required init?(coder aDecoder: NSCoder) {
@ -168,6 +171,12 @@ class MessageActionSheetView: UIView {
private let actionStackView: UIStackView private let actionStackView: UIStackView
private var actions: [MessageAction] private var actions: [MessageAction]
override var bounds: CGRect {
didSet {
updateMask()
}
}
convenience init(actions: [MessageAction]) { convenience init(actions: [MessageAction]) {
self.init(frame: CGRect.zero) self.init(frame: CGRect.zero)
actions.forEach { self.addAction($0) } actions.forEach { self.addAction($0) }
@ -175,15 +184,18 @@ class MessageActionSheetView: UIView {
override init(frame: CGRect) { override init(frame: CGRect) {
actionStackView = UIStackView() actionStackView = UIStackView()
self.actions = [] actionStackView.axis = .vertical
actionStackView.spacing = CGHairlineWidth()
actions = []
super.init(frame: frame) super.init(frame: frame)
backgroundColor = UIColor.ows_light10
addSubview(actionStackView) addSubview(actionStackView)
actionStackView.autoPinToSuperviewEdges() actionStackView.autoPinToSuperviewEdges()
backgroundColor = UIColor.ows_light10 self.clipsToBounds = true
actionStackView.axis = .vertical
} }
required init?(coder aDecoder: NSCoder) { required init?(coder aDecoder: NSCoder) {
@ -192,21 +204,15 @@ class MessageActionSheetView: UIView {
public func addAction(_ action: MessageAction) { public func addAction(_ action: MessageAction) {
let actionView = MessageActionView(action: action) let actionView = MessageActionView(action: action)
if !actions.isEmpty {
self.actionStackView.addArrangedSubview(buildSeparatorView())
}
actions.append(action) actions.append(action)
self.actionStackView.addArrangedSubview(actionView) self.actionStackView.addArrangedSubview(actionView)
} }
private func buildSeparatorView() -> UIView { private func updateMask() {
let separatorView = UIView() let cornerRadius: CGFloat = 16
separatorView.autoSetDimension(.height, toSize: CGHairlineWidth()) let path: UIBezierPath = UIBezierPath(roundedRect: bounds, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: cornerRadius, height: cornerRadius))
separatorView.backgroundColor = UIColor.ows_light10 let mask = CAShapeLayer()
mask.path = path.cgPath
return separatorView self.layer.mask = mask
} }
} }