Skip to content

Commit

Permalink
% Added noImage type for alertView with associated changes to handle …
Browse files Browse the repository at this point in the history
…shadow and header height
  • Loading branch information
Scott Gruby authored and candostdagdeviren committed Mar 14, 2018
1 parent 2f8f6d6 commit 043fccc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
6 changes: 4 additions & 2 deletions CDAlertView/Classes/CDAlertHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private extension CDAlertViewType {
return UIColor(red: 27/255, green: 169/255, blue: 225/255, alpha: 1)
case .alarm:
return UIColor(red: 196/255, green: 52/255, blue: 46/255, alpha: 1)
case .custom:
case .custom, .noImage:
return nil
}
}
Expand Down Expand Up @@ -68,7 +68,7 @@ internal class CDAlertHeaderView: UIView {
alertBackgroundColor.setFill()
path.fill()

if hasRoundCorners == true {
if type?.hasImage() == true {
let curve = UIBezierPath(arcCenter: CGPoint(x: rect.size.width/2, y: 28),
radius: 28,
startAngle:6.84 * CGFloat.pi / 6,
Expand Down Expand Up @@ -133,6 +133,8 @@ internal class CDAlertHeaderView: UIView {
imageView.image = ImageHelper.loadImage(name: imageName)
case .custom(let image):
imageView.image = image
case .noImage:
break
}

imageView.contentMode = .center
Expand Down
27 changes: 21 additions & 6 deletions CDAlertView/Classes/CDAlertView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@
import Foundation

public enum CDAlertViewType {
case error, warning, success, notification, alarm, custom(image: UIImage)
case error, warning, success, notification, alarm, custom(image: UIImage), noImage

// This is needed because we can't do a comparison of enums
// if it has an associated value.
func hasImage() -> Bool {
switch self {
case .noImage:
return false
default:
return true
}
}
}

fileprivate protocol CDAlertViewActionDelegate: class {
Expand Down Expand Up @@ -525,11 +536,15 @@ open class CDAlertView: UIView {
private func createHeaderView() {
headerView = CDAlertHeaderView(type: type, isIconFilled: isHeaderIconFilled)
headerView.backgroundColor = UIColor.clear
headerView.hasShadow = hasShadow
headerView.hasRoundCorners = hasRoundCorners
headerView.alertBackgroundColor = alertBackgroundColor
headerView.circleFillColor = circleFillColor
if circleFillColor == .clear {
if type.hasImage() == true {
headerView.circleFillColor = circleFillColor
headerView.hasShadow = hasShadow
}
else {
headerView.hasShadow = false
headerView.circleFillColor = .clear
headerHeight = constants.headerHeightWithoutCircle
}
popupView.addSubview(headerView)
Expand All @@ -553,9 +568,9 @@ open class CDAlertView: UIView {
height: height),
byRoundingCorners: [.bottomLeft, .bottomRight],
cornerRadii: CGSize(width: 8.0, height: 8.0))
let roundLayer = CAShapeLayer()
roundLayer.path = roundCornersPath.cgPath
if hasRoundCorners == true {
let roundLayer = CAShapeLayer()
roundLayer.path = roundCornersPath.cgPath
buttonView.layer.mask = roundLayer
}
popupView.addSubview(buttonView)
Expand Down

0 comments on commit 043fccc

Please sign in to comment.