Skip to content

Commit

Permalink
- general improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
rursache committed Nov 11, 2021
1 parent 272f360 commit 0d3f236
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
16 changes: 8 additions & 8 deletions Files/RSDatePicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// RSDatePicker
//
// Created by Radu Ursache - RanduSoft
// v1.1.0
// v1.2.0
//

import UIKit
Expand All @@ -14,7 +14,7 @@ import UIKit
@IBOutlet public weak var view: UIView!
private var didLoad: Bool = false

@IBOutlet private weak var calendarImageView: UIDatePicker!
@IBOutlet private weak var calendarImageView: UIImageView!
@IBOutlet private weak var datePicker: UIDatePicker!
@IBOutlet private weak var dateLabel: UILabel!
@IBOutlet private weak var stackViewMarginLeft: NSLayoutConstraint!
Expand All @@ -33,7 +33,7 @@ import UIKit
public var calendarIconIsHidden: Bool = false {
didSet {
self.calendarImageView.isHidden = self.calendarIconIsHidden
self.calendarImageView.alpha = self.calendarIconIsHidden ? 0 : 1
self.dateLabel.textAlignment = self.calendarIconIsHidden ? .center : .left
}
}
public var leftMargin: Double = 8 {
Expand All @@ -58,7 +58,9 @@ import UIKit
}
public var currentDate = Date() {
didSet {
self.didUpdateDate()
DispatchQueue.main.async {
self.didUpdateDate()
}
}
}

Expand Down Expand Up @@ -92,22 +94,20 @@ import UIKit
}

private func prepareDatePicker() {
self.datePicker.layer.zPosition = CGFloat(MAXFLOAT)
self.datePicker.date = self.initialDate ?? Date()
self.currentDate = self.datePicker.date
self.datePicker.minimumDate = self.minimumDate
self.datePicker.maximumDate = self.maximumDate
self.datePicker.datePickerMode = self.pickerMode ?? .date
self.datePicker.alpha = 0.03
self.calendarImageView.isHidden = self.calendarIconIsHidden
self.datePicker.date = self.currentDate
self.updateMargins()
self.didUpdateDate()
}

private func didUpdateDate() {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = self.dateFormat ?? "dd/MM/YYYY"
self.dateLabel.text = dateFormatter.string(from: self.currentDate)
self.datePicker.date = self.currentDate
self.didChangeDate?(self.currentDate)
}

Expand Down
12 changes: 4 additions & 8 deletions Files/RSDatePicker.xib
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="RSDatePicker" customModule="RSDatePicker">
<connections>
<outlet property="calendarImageView" destination="Euo-XS-dzT" id="RME-2a-SKG"/>
<outlet property="calendarImageView" destination="3TP-IY-JNT" id="SBf-Ze-Plo"/>
<outlet property="dateLabel" destination="4uN-Y8-3mv" id="sBR-fE-emF"/>
<outlet property="datePicker" destination="Euo-XS-dzT" id="c3s-d7-rQK"/>
<outlet property="stackViewMarginBottom" destination="pnN-vt-sAS" id="EgQ-Xj-eBb"/>
Expand All @@ -24,19 +24,15 @@
<rect key="frame" x="0.0" y="0.0" width="279" height="70"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="MKE-R0-Ri8">
<stackView opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="MKE-R0-Ri8">
<rect key="frame" x="10" y="8" width="261" height="54"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="252" verticalHuggingPriority="251" horizontalCompressionResistancePriority="754" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4uN-Y8-3mv">
<rect key="frame" x="0.0" y="0.0" width="41.5" height="54"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="252" verticalHuggingPriority="251" horizontalCompressionResistancePriority="754" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4uN-Y8-3mv">
<rect key="frame" x="0.0" y="0.0" width="207" height="54"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<view userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="248" translatesAutoresizingMaskIntoConstraints="NO" id="xwk-0j-NAQ" userLabel="spacer">
<rect key="frame" x="41.5" y="0.0" width="165.5" height="54"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="calendar" catalog="system" translatesAutoresizingMaskIntoConstraints="NO" id="3TP-IY-JNT">
<rect key="frame" x="207" y="1" width="54" height="51.5"/>
<color key="tintColor" systemColor="labelColor"/>
Expand Down

0 comments on commit 0d3f236

Please sign in to comment.