diff --git a/CDAlertView/Classes/CDAlertHeaderView.swift b/CDAlertView/Classes/CDAlertHeaderView.swift index f295402..b5d74db 100644 --- a/CDAlertView/Classes/CDAlertHeaderView.swift +++ b/CDAlertView/Classes/CDAlertHeaderView.swift @@ -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 } } @@ -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, @@ -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 diff --git a/CDAlertView/Classes/CDAlertView.swift b/CDAlertView/Classes/CDAlertView.swift index 6d4250c..a036c4d 100755 --- a/CDAlertView/Classes/CDAlertView.swift +++ b/CDAlertView/Classes/CDAlertView.swift @@ -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 { @@ -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) @@ -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)