Skip to content

Commit 043fccc

Browse files
Scott Grubycandostdagdeviren
authored andcommitted
% Added noImage type for alertView with associated changes to handle shadow and header height
1 parent 2f8f6d6 commit 043fccc

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

CDAlertView/Classes/CDAlertHeaderView.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ private extension CDAlertViewType {
2121
return UIColor(red: 27/255, green: 169/255, blue: 225/255, alpha: 1)
2222
case .alarm:
2323
return UIColor(red: 196/255, green: 52/255, blue: 46/255, alpha: 1)
24-
case .custom:
24+
case .custom, .noImage:
2525
return nil
2626
}
2727
}
@@ -68,7 +68,7 @@ internal class CDAlertHeaderView: UIView {
6868
alertBackgroundColor.setFill()
6969
path.fill()
7070

71-
if hasRoundCorners == true {
71+
if type?.hasImage() == true {
7272
let curve = UIBezierPath(arcCenter: CGPoint(x: rect.size.width/2, y: 28),
7373
radius: 28,
7474
startAngle:6.84 * CGFloat.pi / 6,
@@ -133,6 +133,8 @@ internal class CDAlertHeaderView: UIView {
133133
imageView.image = ImageHelper.loadImage(name: imageName)
134134
case .custom(let image):
135135
imageView.image = image
136+
case .noImage:
137+
break
136138
}
137139

138140
imageView.contentMode = .center

CDAlertView/Classes/CDAlertView.swift

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,18 @@
99
import Foundation
1010

1111
public enum CDAlertViewType {
12-
case error, warning, success, notification, alarm, custom(image: UIImage)
12+
case error, warning, success, notification, alarm, custom(image: UIImage), noImage
13+
14+
// This is needed because we can't do a comparison of enums
15+
// if it has an associated value.
16+
func hasImage() -> Bool {
17+
switch self {
18+
case .noImage:
19+
return false
20+
default:
21+
return true
22+
}
23+
}
1324
}
1425

1526
fileprivate protocol CDAlertViewActionDelegate: class {
@@ -525,11 +536,15 @@ open class CDAlertView: UIView {
525536
private func createHeaderView() {
526537
headerView = CDAlertHeaderView(type: type, isIconFilled: isHeaderIconFilled)
527538
headerView.backgroundColor = UIColor.clear
528-
headerView.hasShadow = hasShadow
529539
headerView.hasRoundCorners = hasRoundCorners
530540
headerView.alertBackgroundColor = alertBackgroundColor
531-
headerView.circleFillColor = circleFillColor
532-
if circleFillColor == .clear {
541+
if type.hasImage() == true {
542+
headerView.circleFillColor = circleFillColor
543+
headerView.hasShadow = hasShadow
544+
}
545+
else {
546+
headerView.hasShadow = false
547+
headerView.circleFillColor = .clear
533548
headerHeight = constants.headerHeightWithoutCircle
534549
}
535550
popupView.addSubview(headerView)
@@ -553,9 +568,9 @@ open class CDAlertView: UIView {
553568
height: height),
554569
byRoundingCorners: [.bottomLeft, .bottomRight],
555570
cornerRadii: CGSize(width: 8.0, height: 8.0))
556-
let roundLayer = CAShapeLayer()
557-
roundLayer.path = roundCornersPath.cgPath
558571
if hasRoundCorners == true {
572+
let roundLayer = CAShapeLayer()
573+
roundLayer.path = roundCornersPath.cgPath
559574
buttonView.layer.mask = roundLayer
560575
}
561576
popupView.addSubview(buttonView)

0 commit comments

Comments
 (0)