Skip to content

Commit

Permalink
Fixes #5 and Fixes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
egmoll7 committed Oct 31, 2017
1 parent 8c2fb6b commit fe22253
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion EMAlertController.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'EMAlertController'
s.version = '1.0.0'
s.version = '1.0.1'
s.summary = 'Elegant alert view controller alternative for iOS'

s.description = <<-DESC
Expand Down
22 changes: 20 additions & 2 deletions EMAlertController/EMAlertController/EMAlertController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enum Dimension {
}
static let padding: CGFloat = 15.0
static let buttonHeight: CGFloat = 50.0
static let iconHeight: CGFloat = 100.0
}

open class EMAlertController: UIViewController {
Expand All @@ -24,8 +25,9 @@ open class EMAlertController: UIViewController {
internal var buttonStackViewHeightConstraint: NSLayoutConstraint?
internal var buttonStackViewWidthConstraint: NSLayoutConstraint?
internal var scrollViewHeightConstraint: NSLayoutConstraint?
internal var imageViewHeight: CGFloat = 100
internal var imageViewHeight: CGFloat = Dimension.iconHeight
internal var messageLabelHeight: CGFloat = 20
internal var iconHeightConstraint: NSLayoutConstraint?

internal lazy var backgroundView: UIView = {
let bgView = UIView()
Expand Down Expand Up @@ -107,6 +109,13 @@ open class EMAlertController: UIViewController {
}
set {
imageView.image = newValue
guard let image = newValue else {
imageViewHeight = 0
iconHeightConstraint?.constant = imageViewHeight
return
}
(image.size.height > CGFloat(0.0)) ? (imageViewHeight = Dimension.iconHeight) : (imageViewHeight = 0)
iconHeightConstraint?.constant = imageViewHeight
}
}

Expand Down Expand Up @@ -140,6 +149,7 @@ open class EMAlertController: UIViewController {
}
}

/// Alert background color
public var backgroundColor: UIColor? {
willSet {
alertView.backgroundColor = newValue
Expand All @@ -158,6 +168,13 @@ open class EMAlertController: UIViewController {
}
}

/// Spacing between actions when presenting two actions in horizontal
public var buttonSpacing: CGFloat = 15 {
willSet {
buttonStackView.spacing = newValue
}
}

// MARK: - Initializers
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
Expand Down Expand Up @@ -243,7 +260,8 @@ extension EMAlertController {
imageView.topAnchor.constraint(equalTo: alertView.topAnchor, constant: 5).isActive = true
imageView.leadingAnchor.constraint(equalTo: alertView.leadingAnchor, constant: Dimension.padding).isActive = true
imageView.trailingAnchor.constraint(equalTo: alertView.trailingAnchor, constant: -Dimension.padding).isActive = true
imageView.heightAnchor.constraint(equalToConstant: imageViewHeight).isActive = true
iconHeightConstraint = imageView.heightAnchor.constraint(equalToConstant: imageViewHeight)
iconHeightConstraint?.isActive = true

// titleLabel Constraints
titleLabel.topAnchor.constraint(equalTo: imageView.bottomAnchor, constant: 8).isActive = true
Expand Down
6 changes: 6 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ action.actionBackgroundColor = UIColor.red
// Default color = UIColor.clear
```

### Button Spacing (Only when two buttons are displayed in horizontal)
```swift
alert.buttonSpacing = 0
// Default spacing = 15
```

## TODO
* [ ] Textfield Support
* [ ] Carthage Support
Expand Down

0 comments on commit fe22253

Please sign in to comment.