Skip to content

Commit f9de73a

Browse files
Rename LayoutConstraintsExtension methods with cd prefix #23
1 parent 0120907 commit f9de73a

File tree

4 files changed

+63
-63
lines changed

4 files changed

+63
-63
lines changed

CDAlertView/Classes/CDAlertHeaderView.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ internal class CDAlertHeaderView: UIView {
131131
imageView.contentMode = .center
132132
addSubview(imageView)
133133
imageView.translatesAutoresizingMaskIntoConstraints = false
134-
imageView.centerHorizontally()
134+
imageView.cd_centerHorizontally()
135135

136-
imageView.alignToTop(of: self, margin: 12, multiplier: 1)
137-
imageView.setHeight(32)
138-
imageView.setWidth(32)
136+
imageView.cd_alignToTop(of: self, margin: 12, multiplier: 1)
137+
imageView.cd_setHeight(32)
138+
imageView.cd_setWidth(32)
139139

140140
return imageView
141141
}

CDAlertView/Classes/CDAlertView.swift

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,9 @@ open class CDAlertView: UIView {
276276
public func show(_ completion:((CDAlertView) -> Void)? = nil) {
277277

278278
UIApplication.shared.keyWindow?.addSubview(self)
279-
alignToParent(with: 0)
279+
cd_alignToParent(with: 0)
280280
addSubview(backgroundView)
281-
backgroundView.alignToParent(with: 0)
281+
backgroundView.cd_alignToParent(with: 0)
282282
if !isActionButtonsVertical && actions.count > 3 {
283283
debugPrint("CDAlertView: You can't use more than 3 actions in horizontal mode. If you need more than 3 buttons, consider using vertical alignment for buttons. Setting vertical alignments for buttons is available via isActionButtonsVertical property of AlertView")
284284
actions.removeSubrange(3..<actions.count)
@@ -453,10 +453,10 @@ open class CDAlertView: UIView {
453453
}
454454

455455
popupView.translatesAutoresizingMaskIntoConstraints = false
456-
popupView.centerHorizontally()
457-
popupView.centerVertically()
458-
popupView.setWidth(popupWidth)
459-
popupView.setMaxHeight(430)
456+
popupView.cd_centerHorizontally()
457+
popupView.cd_centerVertically()
458+
popupView.cd_setWidth(popupWidth)
459+
popupView.cd_setMaxHeight(430)
460460
popupView.sizeToFit()
461461
popupView.layoutIfNeeded()
462462
if actions.count == 0 {
@@ -476,10 +476,10 @@ open class CDAlertView: UIView {
476476
headerView.circleFillColor = circleFillColor
477477
popupView.addSubview(headerView)
478478
headerView.translatesAutoresizingMaskIntoConstraints = false
479-
headerView.alignTopToParent(with: 0)
480-
headerView.alignLeftToParent(with: 0)
481-
headerView.alignRightToParent(with: 0)
482-
headerView.setHeight(constants.headerHeight)
479+
headerView.cd_alignTopToParent(with: 0)
480+
headerView.cd_alignLeftToParent(with: 0)
481+
headerView.cd_alignRightToParent(with: 0)
482+
headerView.cd_setHeight(constants.headerHeight)
483483
}
484484

485485
private func createButtonContainer() {
@@ -500,57 +500,57 @@ open class CDAlertView: UIView {
500500
buttonView.layer.mask = roundLayer
501501
popupView.addSubview(buttonView)
502502
buttonView.translatesAutoresizingMaskIntoConstraints = false
503-
buttonView.alignBottomToParent(with: 0)
504-
buttonView.alignLeftToParent(with: 0)
505-
buttonView.alignRightToParent(with: 0)
503+
buttonView.cd_alignBottomToParent(with: 0)
504+
buttonView.cd_alignLeftToParent(with: 0)
505+
buttonView.cd_alignRightToParent(with: 0)
506506
if actions.count == 0 {
507-
buttonView.setHeight(0)
507+
buttonView.cd_setHeight(0)
508508
} else {
509509

510510
let backgroundColoredView = UIView(frame: .zero)
511511
backgroundColoredView.backgroundColor = actionSeparatorColor
512512
buttonView.addSubview(backgroundColoredView)
513-
backgroundColoredView.alignToParent(with: 0)
513+
backgroundColoredView.cd_alignToParent(with: 0)
514514

515515
buttonContainer.spacing = constants.separatorThickness
516516
if isActionButtonsVertical {
517517
buttonContainer.axis = .vertical
518518
} else {
519519
buttonContainer.axis = .horizontal
520520
}
521-
buttonView.setHeight(height)
521+
buttonView.cd_setHeight(height)
522522
buttonContainer.translatesAutoresizingMaskIntoConstraints = false
523523
backgroundColoredView.addSubview(buttonContainer)
524-
buttonContainer.alignTopToParent(with: constants.separatorThickness)
525-
buttonContainer.alignBottomToParent(with: 0)
526-
buttonContainer.alignLeftToParent(with: 0)
527-
buttonContainer.alignRightToParent(with: 0)
524+
buttonContainer.cd_alignTopToParent(with: constants.separatorThickness)
525+
buttonContainer.cd_alignBottomToParent(with: 0)
526+
buttonContainer.cd_alignLeftToParent(with: 0)
527+
buttonContainer.cd_alignRightToParent(with: 0)
528528
}
529529
}
530530

531531
private func createStackView() {
532532
coverView.backgroundColor = alertBackgroundColor
533533
popupView.addSubview(coverView)
534534
coverView.translatesAutoresizingMaskIntoConstraints = false
535-
coverView.alignLeftToParent(with: 0)
536-
coverView.alignRightToParent(with: 0)
537-
coverView.place(below: headerView, margin: 0)
538-
coverView.place(above: buttonView, margin: 0)
535+
coverView.cd_alignLeftToParent(with: 0)
536+
coverView.cd_alignRightToParent(with: 0)
537+
coverView.cd_place(below: headerView, margin: 0)
538+
coverView.cd_place(above: buttonView, margin: 0)
539539
contentStackView.distribution = .equalSpacing
540540
contentStackView.axis = .vertical
541541
contentStackView.spacing = 8
542542
coverView.addSubview(contentStackView)
543543
contentStackView.translatesAutoresizingMaskIntoConstraints = false
544-
contentStackView.alignTopToParent(with: 0)
545-
contentStackView.alignBottomToParent(with: 16)
546-
contentStackView.alignRightToParent(with: 16)
547-
contentStackView.alignLeftToParent(with: 16)
544+
contentStackView.cd_alignTopToParent(with: 0)
545+
contentStackView.cd_alignBottomToParent(with: 16)
546+
contentStackView.cd_alignRightToParent(with: 16)
547+
contentStackView.cd_alignLeftToParent(with: 16)
548548
}
549549

550550
private func createTitleLabel() {
551551
titleLabel.numberOfLines = 0
552552
titleLabel.textAlignment = .center
553-
titleLabel.setMaxHeight(100)
553+
titleLabel.cd_setMaxHeight(100)
554554
titleLabel.textColor = titleTextColor
555555
titleLabel.font = titleFont
556556
contentStackView.addArrangedSubview(titleLabel)
@@ -560,7 +560,7 @@ open class CDAlertView: UIView {
560560
messageLabel.numberOfLines = 0
561561
messageLabel.textAlignment = .center
562562
messageLabel.textColor = messageTextColor
563-
messageLabel.setMaxHeight(290)
563+
messageLabel.cd_setMaxHeight(290)
564564
messageLabel.font = messageFont
565565
contentStackView.addArrangedSubview(messageLabel)
566566
}
@@ -585,7 +585,7 @@ open class CDAlertView: UIView {
585585
textField.isHidden = isTextFieldHidden
586586
textField.placeholder = textFieldPlaceholderText
587587
textField.autocapitalizationType = textFieldAutocapitalizationType
588-
textField.setHeight(textFieldHeight)
588+
textField.cd_setHeight(textFieldHeight)
589589
contentStackView.addArrangedSubview(textField)
590590
}
591591

@@ -614,12 +614,12 @@ open class CDAlertView: UIView {
614614
buttonContainer.addArrangedSubview(button)
615615
button.translatesAutoresizingMaskIntoConstraints = false
616616
if isActionButtonsVertical {
617-
button.setWidth(buttonContainer.frame.size.width)
617+
button.cd_setWidth(buttonContainer.frame.size.width)
618618
} else {
619-
button.setWidth((buttonContainer.frame.size.width-CGFloat(actions.count-1) * constants.separatorThickness)/CGFloat(actions.count))
619+
button.cd_setWidth((buttonContainer.frame.size.width-CGFloat(actions.count-1) * constants.separatorThickness)/CGFloat(actions.count))
620620
}
621621

622-
button.setHeight(CGFloat(buttonsHeight))
622+
button.cd_setHeight(CGFloat(buttonsHeight))
623623
}
624624
}
625625
}

CDAlertView/Classes/LayoutConstraintsExtension.swift

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

1111
internal extension UIView {
12-
func alignToTop(of view: UIView, margin: CGFloat, multiplier: CGFloat) {
12+
func cd_alignToTop(of view: UIView, margin: CGFloat, multiplier: CGFloat) {
1313
self.superview!.addConstraint(NSLayoutConstraint(item: self,
1414
attribute: .top,
1515
relatedBy: .equal,
@@ -19,15 +19,15 @@ internal extension UIView {
1919
constant: margin))
2020
}
2121

22-
func alignTopToParent(with margin: CGFloat) {
23-
alignToTop(of: self.superview!, margin: margin, multiplier: 1)
22+
func cd_alignTopToParent(with margin: CGFloat) {
23+
cd_alignToTop(of: self.superview!, margin: margin, multiplier: 1)
2424
}
2525

26-
func alignBottomToParent(with margin: CGFloat) {
27-
alignToBottom(of: self.superview!, margin: margin)
26+
func cd_alignBottomToParent(with margin: CGFloat) {
27+
cd_alignToBottom(of: self.superview!, margin: margin)
2828
}
2929

30-
func alignToBottom(of view: UIView, margin: CGFloat) {
30+
func cd_alignToBottom(of view: UIView, margin: CGFloat) {
3131
self.superview!.addConstraint(NSLayoutConstraint(item: self,
3232
attribute: .bottom,
3333
relatedBy: .equal,
@@ -37,11 +37,11 @@ internal extension UIView {
3737
constant: -margin))
3838
}
3939

40-
func alignLeftToParent(with margin: CGFloat) {
41-
alignToLeft(of: self.superview!, margin: margin)
40+
func cd_alignLeftToParent(with margin: CGFloat) {
41+
cd_alignToLeft(of: self.superview!, margin: margin)
4242
}
4343

44-
func alignToLeft(of view: UIView, margin: CGFloat) {
44+
func cd_alignToLeft(of view: UIView, margin: CGFloat) {
4545
self.superview!.addConstraint(NSLayoutConstraint(item: self,
4646
attribute: .left,
4747
relatedBy: .equal,
@@ -51,11 +51,11 @@ internal extension UIView {
5151
constant: margin))
5252
}
5353

54-
func alignRightToParent(with margin: CGFloat) {
55-
alignToRight(of: self.superview!, margin: margin)
54+
func cd_alignRightToParent(with margin: CGFloat) {
55+
cd_alignToRight(of: self.superview!, margin: margin)
5656
}
5757

58-
func alignToRight(of view: UIView, margin: CGFloat) {
58+
func cd_alignToRight(of view: UIView, margin: CGFloat) {
5959
self.superview!.addConstraint(NSLayoutConstraint(item: self,
6060
attribute: .right,
6161
relatedBy: .equal,
@@ -65,15 +65,15 @@ internal extension UIView {
6565
constant: -margin))
6666
}
6767

68-
func alignToParent(with margin: CGFloat) {
68+
func cd_alignToParent(with margin: CGFloat) {
6969
translatesAutoresizingMaskIntoConstraints = false
70-
alignTopToParent(with: margin)
71-
alignLeftToParent(with: margin)
72-
alignRightToParent(with: margin)
73-
alignBottomToParent(with: margin)
70+
cd_alignTopToParent(with: margin)
71+
cd_alignLeftToParent(with: margin)
72+
cd_alignRightToParent(with: margin)
73+
cd_alignBottomToParent(with: margin)
7474
}
7575

76-
func setHeight(_ height: CGFloat) {
76+
func cd_setHeight(_ height: CGFloat) {
7777
self.addConstraint(NSLayoutConstraint(item: self,
7878
attribute: .height,
7979
relatedBy: .equal,
@@ -83,7 +83,7 @@ internal extension UIView {
8383
constant: height))
8484
}
8585

86-
func setMaxHeight(_ height: CGFloat) {
86+
func cd_setMaxHeight(_ height: CGFloat) {
8787
self.addConstraint(NSLayoutConstraint(item: self,
8888
attribute: .height,
8989
relatedBy: .lessThanOrEqual,
@@ -93,7 +93,7 @@ internal extension UIView {
9393
constant: height))
9494
}
9595

96-
func setWidth(_ width: CGFloat) {
96+
func cd_setWidth(_ width: CGFloat) {
9797
self.addConstraint(NSLayoutConstraint(item: self,
9898
attribute: .width,
9999
relatedBy: .equal,
@@ -103,7 +103,7 @@ internal extension UIView {
103103
constant: width))
104104
}
105105

106-
func centerHorizontally() {
106+
func cd_centerHorizontally() {
107107
self.superview!.addConstraint(NSLayoutConstraint(item: self,
108108
attribute: .centerX,
109109
relatedBy: .equal,
@@ -113,7 +113,7 @@ internal extension UIView {
113113
constant: 0))
114114
}
115115

116-
func centerVertically() {
116+
func cd_centerVertically() {
117117
self.superview!.addConstraint(NSLayoutConstraint(item: self,
118118
attribute: .centerY,
119119
relatedBy: .equal,
@@ -123,7 +123,7 @@ internal extension UIView {
123123
constant: 0))
124124
}
125125

126-
func place(below view: UIView, margin: CGFloat) {
126+
func cd_place(below view: UIView, margin: CGFloat) {
127127
self.superview!.addConstraint(NSLayoutConstraint(item: self,
128128
attribute: .top,
129129
relatedBy: .equal,
@@ -133,7 +133,7 @@ internal extension UIView {
133133
constant: margin))
134134
}
135135

136-
func place(above view: UIView, margin: CGFloat) {
136+
func cd_place(above view: UIView, margin: CGFloat) {
137137
self.superview!.addConstraint(NSLayoutConstraint(item: self,
138138
attribute: .bottom,
139139
relatedBy: .equal,

Example/CDAlertViewExample.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
);
187187
runOnlyForDeploymentPostprocessing = 0;
188188
shellPath = /bin/sh;
189-
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
189+
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
190190
showEnvVarsInLog = 0;
191191
};
192192
D561740633B64D2FBA5F8C1A /* [CP] Embed Pods Frameworks */ = {

0 commit comments

Comments
 (0)