Skip to content

Commit

Permalink
Merge pull request #61 from pasevin/master
Browse files Browse the repository at this point in the history
Added custom paddings to multiple views
  • Loading branch information
pmusolino authored Apr 22, 2018
2 parents 4232741 + 7454c7b commit 1c10600
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 16 deletions.
17 changes: 13 additions & 4 deletions Library/PMAlertController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,20 @@ import UIKit
@IBOutlet weak open var alertViewWidthConstraint: NSLayoutConstraint!
@IBOutlet weak open var headerView: UIView!
@IBOutlet weak open var headerViewHeightConstraint: NSLayoutConstraint!
@IBOutlet weak open var headerViewTopSpaceConstraint: NSLayoutConstraint!
@IBOutlet weak open var alertImage: UIImageView!
@IBOutlet weak open var alertTitle: UILabel!
@IBOutlet weak open var alertDescription: UILabel!
@IBOutlet weak open var alertContentStackViewLeadingConstraint: NSLayoutConstraint!
@IBOutlet weak open var alertContentStackViewTrailingConstraint: NSLayoutConstraint!
@IBOutlet weak open var alertContentStackViewTopConstraint: NSLayoutConstraint!
@IBOutlet weak open var alertActionStackView: UIStackView!
@IBOutlet weak open var alertStackViewHeightConstraint: NSLayoutConstraint!
@IBOutlet weak open var alertActionStackViewHeightConstraint: NSLayoutConstraint!
@IBOutlet weak open var alertActionStackViewLeadingConstraint: NSLayoutConstraint!
@IBOutlet weak open var alertActionStackViewTrailingConstraint: NSLayoutConstraint!
@IBOutlet weak open var alertActionStackViewTopConstraint: NSLayoutConstraint!
@IBOutlet weak open var alertActionStackViewBottomConstraint: NSLayoutConstraint!

open var ALERT_STACK_VIEW_HEIGHT : CGFloat = UIScreen.main.bounds.height < 568.0 ? 40 : 62 //if iphone 4 the stack_view_height is 40, else 62
var animator : UIDynamicAnimator?

Expand Down Expand Up @@ -81,11 +90,11 @@ import UIKit
alertActionStackView.addArrangedSubview(alertAction)

if alertActionStackView.arrangedSubviews.count > 2 || hasTextFieldAdded(){
alertStackViewHeightConstraint.constant = ALERT_STACK_VIEW_HEIGHT * CGFloat(alertActionStackView.arrangedSubviews.count)
alertActionStackViewHeightConstraint.constant = ALERT_STACK_VIEW_HEIGHT * CGFloat(alertActionStackView.arrangedSubviews.count)
alertActionStackView.axis = .vertical
}
else{
alertStackViewHeightConstraint.constant = ALERT_STACK_VIEW_HEIGHT
alertActionStackViewHeightConstraint.constant = ALERT_STACK_VIEW_HEIGHT
alertActionStackView.axis = .horizontal
}

Expand Down Expand Up @@ -118,7 +127,7 @@ import UIKit
}
func _addTextField(_ textField: UITextField){
alertActionStackView.addArrangedSubview(textField)
alertStackViewHeightConstraint.constant = ALERT_STACK_VIEW_HEIGHT * CGFloat(alertActionStackView.arrangedSubviews.count)
alertActionStackViewHeightConstraint.constant = ALERT_STACK_VIEW_HEIGHT * CGFloat(alertActionStackView.arrangedSubviews.count)
alertActionStackView.axis = .vertical
textFields.append(textField)
}
Expand Down
22 changes: 12 additions & 10 deletions Library/PMAlertController.xib
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13527"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<customFonts key="customFonts">
<array key="Avenir.ttc">
<string>Avenir-Medium</string>
<string>Avenir-Roman</string>
</array>
</customFonts>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="PMAlertController" customModule="PMAlertController" customModuleProvider="target">
<connections>
<outlet property="alertActionStackView" destination="WJc-5g-auJ" id="6ho-4f-C1R"/>
<outlet property="alertActionStackViewBottomConstraint" destination="P7Y-tt-2D9" id="JA5-K8-NPg"/>
<outlet property="alertActionStackViewHeightConstraint" destination="sZH-1X-biu" id="air-m7-rmW"/>
<outlet property="alertActionStackViewLeadingConstraint" destination="Qvh-W5-xGk" id="MWM-nd-by1"/>
<outlet property="alertActionStackViewTopConstraint" destination="rQm-Go-qos" id="0zz-iC-4rb"/>
<outlet property="alertActionStackViewTrailingConstraint" destination="bPd-4c-qNR" id="Lgw-Ed-D7Q"/>
<outlet property="alertContentStackViewLeadingConstraint" destination="JoG-bm-Y31" id="qe7-LF-6uF"/>
<outlet property="alertContentStackViewTopConstraint" destination="cZ2-BF-gBn" id="3Fz-vD-bEV"/>
<outlet property="alertContentStackViewTrailingConstraint" destination="faR-Xx-08y" id="cir-vE-ibe"/>
<outlet property="alertDescription" destination="BaL-rf-G7t" id="oA9-n7-8tS"/>
<outlet property="alertImage" destination="Rwc-nf-sc4" id="9c2-Rv-Z2W"/>
<outlet property="alertMaskBackground" destination="QvX-0K-co6" id="U8C-Dt-d5N"/>
<outlet property="alertStackViewHeightConstraint" destination="sZH-1X-biu" id="air-m7-rmW"/>
<outlet property="alertTitle" destination="boW-P6-B3N" id="Q1I-HI-El2"/>
<outlet property="alertView" destination="dEl-s8-6vU" id="sSB-hF-osA"/>
<outlet property="alertViewWidthConstraint" destination="2KX-8C-U18" id="7hM-KT-GdH"/>
<outlet property="headerView" destination="jTz-eN-yAz" id="10g-pC-ZH9"/>
<outlet property="headerViewHeightConstraint" destination="mA2-xx-mfB" id="1GQ-Wz-iVX"/>
<outlet property="headerViewTopSpaceConstraint" destination="AT5-Y6-bpb" id="vFb-EK-yfz"/>
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
</connections>
</placeholder>
Expand Down Expand Up @@ -58,7 +60,7 @@
<constraint firstAttribute="trailing" secondItem="Rwc-nf-sc4" secondAttribute="trailing" id="ptn-Q8-BP8"/>
</constraints>
</view>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="LMB-jY-4In">
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="LMB-jY-4In" userLabel="Alert Content Stack View">
<rect key="frame" x="8" y="198" width="341" height="52.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" " textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="boW-P6-B3N">
Expand Down
19 changes: 17 additions & 2 deletions PMAlertControllerSample/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13527"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down Expand Up @@ -86,6 +86,19 @@
<action selector="showAlertWithTextEntry:" destination="BYZ-38-t0r" eventType="touchUpInside" id="MWL-bK-Dc4"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="dAa-Tp-rp4">
<rect key="frame" x="71" y="447.5" width="232" height="30"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="200" id="gBq-9k-IRB"/>
<constraint firstAttribute="height" constant="30" id="ooF-jr-ABn"/>
</constraints>
<state key="normal" title="Show Alert with Custom Paddings">
<color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="showWalkthroughWithCustomPaddings:" destination="BYZ-38-t0r" eventType="touchUpInside" id="QFg-3e-Krb"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
Expand All @@ -97,7 +110,9 @@
<constraint firstItem="9Tf-BW-og0" firstAttribute="centerX" secondItem="WaF-QJ-Xl8" secondAttribute="centerX" id="h6x-7g-Wc3"/>
<constraint firstAttribute="bottom" secondItem="aCJ-yh-itC" secondAttribute="bottom" id="hKX-9R-uUt"/>
<constraint firstItem="BoA-fU-ZBo" firstAttribute="top" secondItem="9Tf-BW-og0" secondAttribute="bottom" constant="8" id="hnU-1N-1OM"/>
<constraint firstItem="dAa-Tp-rp4" firstAttribute="top" secondItem="BoA-fU-ZBo" secondAttribute="bottom" constant="8" id="k72-Ee-ISx"/>
<constraint firstItem="aCJ-yh-itC" firstAttribute="leading" secondItem="WaF-QJ-Xl8" secondAttribute="leading" id="lHz-ks-chV"/>
<constraint firstItem="dAa-Tp-rp4" firstAttribute="centerX" secondItem="WaF-QJ-Xl8" secondAttribute="centerX" id="phN-Up-EFz"/>
<constraint firstItem="WaF-QJ-Xl8" firstAttribute="trailing" secondItem="aCJ-yh-itC" secondAttribute="trailing" id="puC-EB-QJD"/>
<constraint firstItem="4HV-8v-2tv" firstAttribute="top" secondItem="9lY-Kd-UGp" secondAttribute="bottom" constant="8" id="sGw-vH-IWu"/>
<constraint firstItem="9lY-Kd-UGp" firstAttribute="centerX" secondItem="WaF-QJ-Xl8" secondAttribute="centerX" id="tTH-uB-Y22"/>
Expand Down
26 changes: 26 additions & 0 deletions PMAlertControllerSample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,30 @@ class ViewController: UIViewController {

self.present(alertVC, animated: true, completion: nil)
}

@IBAction func showWalkthroughWithCustomPaddings(_ sender: AnyObject) {
let alertVC = PMAlertController(title: "Locate your device", description: "Enables access to your location: discover what you can do when you're traveling and what is available near you.", image: UIImage(named: "flag.png"), style: .walkthrough) //Image by freepik.com, taken on flaticon.com


alertVC.headerViewTopSpaceConstraint.constant = 20
alertVC.alertContentStackViewLeadingConstraint.constant = 20
alertVC.alertContentStackViewTrailingConstraint.constant = 20
alertVC.alertContentStackViewTopConstraint.constant = 20
alertVC.alertActionStackViewLeadingConstraint.constant = 20
alertVC.alertActionStackViewTrailingConstraint.constant = 20
alertVC.alertActionStackViewTopConstraint.constant = 20
alertVC.alertActionStackViewBottomConstraint.constant = 20
alertVC.view.layoutIfNeeded()

alertVC.addAction(PMAlertAction(title: "Cancel", style: .cancel, action: { () -> Void in
print("Cancel")
}))

alertVC.addAction(PMAlertAction(title: "Allow", style: .default, action: { () in
print("Allow")
}))

self.present(alertVC, animated: true, completion: nil)
}

}

0 comments on commit 1c10600

Please sign in to comment.