Skip to content

Commit

Permalink
% Added ability to turn off round corners
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Gruby authored and candostdagdeviren committed Mar 14, 2018
1 parent a736566 commit 628db4e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
23 changes: 15 additions & 8 deletions CDAlertView/Classes/CDAlertHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ internal class CDAlertHeaderView: UIView {
internal var isIconFilled: Bool = false
internal var alertBackgroundColor: UIColor = UIColor.white.withAlphaComponent(0.9)
internal var hasShadow: Bool = true
internal var hasRoundCorners = true
private var fillColor: UIColor!
private var type: CDAlertViewType?
private var imageView: UIImageView?
Expand All @@ -57,19 +58,25 @@ internal class CDAlertHeaderView: UIView {
// MARK: UIView

override func draw(_ rect: CGRect) {
var cornerRadii = CGSize(width: 8, height: 8)
if hasRoundCorners == false {
cornerRadii = CGSize(width: 0, height: 0)
}
let path = UIBezierPath(roundedRect: CGRect(x: 0, y: 16, width: rect.size.width, height: rect.size.height-16),
byRoundingCorners: [.topLeft, .topRight],
cornerRadii: CGSize(width: 8, height: 8))
cornerRadii: cornerRadii)
alertBackgroundColor.setFill()
path.fill()

let curve = UIBezierPath(arcCenter: CGPoint(x: rect.size.width/2, y: 28),
radius: 28,
startAngle:6.84 * CGFloat.pi / 6,
endAngle: 11.155 * CGFloat.pi / 6,
clockwise: true)
alertBackgroundColor.setFill()
curve.fill()
if hasRoundCorners == true {
let curve = UIBezierPath(arcCenter: CGPoint(x: rect.size.width/2, y: 28),
radius: 28,
startAngle:6.84 * CGFloat.pi / 6,
endAngle: 11.155 * CGFloat.pi / 6,
clockwise: true)
alertBackgroundColor.setFill()
curve.fill()
}

let innerCircle = UIBezierPath(arcCenter: CGPoint(x: rect.size.width/2, y: 28),
radius: 24,
Expand Down
8 changes: 7 additions & 1 deletion CDAlertView/Classes/CDAlertView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ open class CDAlertView: UIView {
}
}

public var hasRoundCorners = true

public var customView: UIView?

public var hideAnimations: CDAlertAnimationBlock?
Expand Down Expand Up @@ -472,6 +474,7 @@ open class CDAlertView: UIView {


private func roundBottomOfCoverView() {
guard hasRoundCorners == false else {return}
let roundCornersPath = UIBezierPath(roundedRect: CGRect(x: 0.0,
y: 0.0,
width: popupWidth,
Expand Down Expand Up @@ -521,6 +524,7 @@ open class CDAlertView: UIView {
headerView = CDAlertHeaderView(type: type, isIconFilled: isHeaderIconFilled)
headerView.backgroundColor = UIColor.clear
headerView.hasShadow = hasShadow
headerView.hasRoundCorners = hasRoundCorners
headerView.alertBackgroundColor = alertBackgroundColor
headerView.circleFillColor = circleFillColor
popupView.addSubview(headerView)
Expand All @@ -546,7 +550,9 @@ open class CDAlertView: UIView {
cornerRadii: CGSize(width: 8.0, height: 8.0))
let roundLayer = CAShapeLayer()
roundLayer.path = roundCornersPath.cgPath
buttonView.layer.mask = roundLayer
if hasRoundCorners == true {
buttonView.layer.mask = roundLayer
}
popupView.addSubview(buttonView)
buttonView.translatesAutoresizingMaskIntoConstraints = false
buttonView.cd_alignBottomToParent(with: 0)
Expand Down

0 comments on commit 628db4e

Please sign in to comment.