Compare commits

..

29 Commits

Author SHA1 Message Date
Ivan Vorobei 0d1381d941 Update to 1.4.8
Change logic for dismiss controller when scroll down in `UIScrollView`.
2019-02-19 20:01:53 +03:00
Ivan Vorobei 39c30a030d Update SPStorkController.podspec 2019-02-19 12:31:58 +03:00
Ivan Vorobei 9e4f6e086f Update to 1.4.6
Added dismiss trigger when scrollView is scrolling down. Also added `swipeToDismissEnabled` checking to allow scrollView bounce when `swipeToDismissEnabled` is disabled.
2019-02-19 12:17:46 +03:00
Ivan Vorobei 5bc31cdc57 Merge pull request #37 from ilia3546/master
Added dismiss trigger when scrollView is scrolling down. Also added `swipeToDismissEnabled` checking to allow scrollView bounce when `swipeToDismissEnabled` is disabled.
2019-02-19 12:05:30 +03:00
Ilya Kharlamov 7d53ed31e6 Fix 2019-02-18 14:26:57 +03:00
Ilya Kharlamov 80806de694 Fix 2019-02-18 14:20:58 +03:00
Ilya Kharlamov 8d8458cc34 Revert "Custom width;"
This reverts commit dd2b29f27a.
2019-02-18 13:58:19 +03:00
Ilya Kharlamov 6e09df910e Custom width;
Ability to disable snapshot scaling;
2019-02-18 13:50:00 +03:00
Ilya Kharlamov 253f60cfa9 ScrollView with disabled swipeToDismissEnabled fixed;
Added trigger for dismissing when view is scrolling down;
2019-02-18 13:10:29 +03:00
Ivan Vorobei 81ed7b01cd Fix some bugs
Fix bug when present 2 or more controllers with custom heights. Also fix bug with grade for `presentingController` view.
2019-02-14 00:23:35 +03:00
Ivan Vorobei d0f120d49c Remove old code 2019-02-09 15:04:10 +03:00
Ivan Vorobei bc3555e715 Update README.md 2019-02-09 09:50:20 +03:00
Ivan Vorobei 432a1206cf Update README.md 2019-02-09 09:48:04 +03:00
Ivan Vorobei 488b19fc46 Update README.md 2019-02-09 09:29:22 +03:00
Ivan Vorobei edc2b6ea41 Fix example of table view 2019-02-09 09:27:13 +03:00
Ivan Vorobei 79d64599d0 Update SPStorkController.podspec 2019-02-08 19:02:59 +03:00
Ivan Vorobei 854ab2aef2 Fix bug
for update translation for scroll when presentng controller
2019-02-08 19:00:17 +03:00
Ivan Vorobei 04c4929e7d Update Readme.md 2019-02-08 18:20:47 +03:00
Ivan Vorobei 6e4e9713c3 Update example 2019-02-07 23:06:41 +03:00
Ivan Vorobei e37c43c8f3 Update SPStorkController.podspec 2019-02-07 11:45:07 +03:00
Ivan Vorobei 001536c835 Fix presented and dismiss action
Now if dismiss controller - keyboard will hide without delay. Also for func `presentAsStork` added property `height`. For SPStorkPresentingAnimationController fix start sizes
2019-02-06 10:53:58 +03:00
Ivan Vorobei 5a7d01e1e4 Update to 1.4.2
Add parameter `translateForDismiss`, which customise translation for dismiss controller. Default is `240`. Rename some parametrs.
2019-02-05 09:45:53 +03:00
Ivan Vorobei a1d17d994c Update to 1.4
If tap on `indicatorView`, controller will be close as in app Apple Music by Apple
2019-02-04 20:41:20 +03:00
Ivan Vorobei f56a054b91 Update SPStorkController.podspec 2019-02-04 01:41:40 +03:00
Ivan Vorobei bd26c4d721 Update SPStorkController.podspec 2019-02-04 01:39:58 +03:00
Ivan Vorobei 6927d90572 Update SPStorkController.podspec 2019-02-04 01:37:03 +03:00
Ivan Vorobei ea32992f63 Update to 1.2.8 2019-02-04 01:34:25 +03:00
Ivan Vorobei 05ba026c1f Update to 1.2.6
Add extenshion to UIViewController. Property `isPresentedAsStork` check if currenct controller present with this pod. For simple usage add func `presentAsStork` - need pass controller only.
2019-02-04 01:20:29 +03:00
Ivan Vorobei b3f49a2a94 Update SPStorkController.podspec 2019-02-01 03:15:56 +03:00
133 changed files with 1701 additions and 1519 deletions
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -21,7 +21,7 @@ class Controller: UIViewController {
self.presentTableControllerButton.addTarget(self, action: #selector(self.presentModalTableViewController), for: .touchUpInside)
self.presentTableControllerButton.sizeToFit()
self.presentTableControllerButton.center.x = self.view.frame.width / 2
self.presentTableControllerButton.frame.origin.y = self.presentControllerButton.frame.bottomYPosition + 10
self.presentTableControllerButton.frame.origin.y = self.presentControllerButton.frame.bottomY + 10
self.view.addSubview(self.presentTableControllerButton)
}
+15 -9
View File
@@ -28,13 +28,28 @@ public struct SPStorkController {
if let presentationController = controller.presentationController as? SPStorkPresentationController {
let translation = -(scrollView.contentOffset.y + scrollView.contentInset.top)
if translation >= 0 {
if controller.isBeingPresented { return }
scrollView.subviews.forEach {
$0.transform = CGAffineTransform(translationX: 0, y: -translation)
}
presentationController.setIndicator(style: scrollView.isDragging ? .line : .arrow)
if translation >= presentationController.translateForDismiss * 0.65 {
if !scrollView.isDragging {
presentationController.presentedViewController.dismiss(animated: true, completion: nil)
return
}
}
if presentationController.pan?.state != UIGestureRecognizer.State.changed {
presentationController.scrollViewDidScroll(translation)
}
} else {
presentationController.setIndicator(style: .arrow)
presentationController.scrollViewDidScroll(0)
}
}
@@ -63,12 +78,3 @@ public struct SPStorkController {
private init() {}
}
extension UIViewController {
var isPresentedAsStork: Bool {
return transitioningDelegate is SPStorkTransitioningDelegate
&& modalPresentationStyle == .custom
&& presentingViewController != nil
}
}
@@ -23,11 +23,13 @@ import UIKit
class SPStorkPresentationController: UIPresentationController, UIGestureRecognizerDelegate {
var isSwipeToDismissEnabled: Bool = true
var isTapAroundToDismissEnabled: Bool = true
var swipeToDismissEnabled: Bool = true
var tapAroundToDismissEnabled: Bool = true
var showIndicator: Bool = true
var indicatorColor: UIColor = UIColor.init(red: 202/255, green: 201/255, blue: 207/255, alpha: 1)
var customHeight: CGFloat? = nil
var translateForDismiss: CGFloat = 240
var transitioningDelegate: SPStorkTransitioningDelegate?
var pan: UIPanGestureRecognizer?
@@ -84,6 +86,9 @@ class SPStorkPresentationController: UIPresentationController, UIGestureRecogniz
if self.showIndicator {
self.indicatorView.color = self.indicatorColor
let tap = UITapGestureRecognizer.init(target: self, action: #selector(self.dismissAction))
tap.cancelsTouchesInView = false
self.indicatorView.addGestureRecognizer(tap)
presentedView.addSubview(self.indicatorView)
}
self.updateLayoutIndicator()
@@ -130,8 +135,9 @@ class SPStorkPresentationController: UIPresentationController, UIGestureRecogniz
containerView.insertSubview(snapshotView, aboveSubview: self.backgroundView)
snapshotView.frame = initialFrame
snapshotView.transform = transformForSnapshotView
snapshotView.alpha = self.alpha
snapshotView.alpha = 1 - self.alpha
snapshotView.layer.cornerRadius = self.cornerRadius
snapshotView.contentMode = .top
snapshotView.layer.masksToBounds = true
rootSnapshotView = snapshotView
@@ -166,13 +172,13 @@ class SPStorkPresentationController: UIPresentationController, UIGestureRecogniz
self.snapshotViewContainer.centerXAnchor.constraint(equalTo: containerView.centerXAnchor).isActive = true
self.updateSnapshotAspectRatio()
if self.isTapAroundToDismissEnabled {
self.tap = UITapGestureRecognizer.init(target: self, action: #selector(self.handleTap))
if self.tapAroundToDismissEnabled {
self.tap = UITapGestureRecognizer.init(target: self, action: #selector(self.dismissAction))
self.tap?.cancelsTouchesInView = false
self.snapshotViewContainer.addGestureRecognizer(self.tap!)
}
if self.isSwipeToDismissEnabled {
if self.swipeToDismissEnabled {
self.pan = UIPanGestureRecognizer(target: self, action: #selector(self.handlePan))
self.pan!.delegate = self
self.pan!.maximumNumberOfTouches = 1
@@ -181,7 +187,9 @@ class SPStorkPresentationController: UIPresentationController, UIGestureRecogniz
}
}
@objc func handleTap() {
@objc func dismissAction() {
self.presentingViewController.view.endEditing(true)
self.presentedViewController.view.endEditing(true)
self.presentedViewController.dismiss(animated: true, completion: nil)
}
@@ -220,6 +228,7 @@ class SPStorkPresentationController: UIPresentationController, UIGestureRecogniz
containerView.insertSubview(snapshotView, aboveSubview: backgroundView)
snapshotView.frame = initialFrame
snapshotView.transform = initialTransform
snapshotView.contentMode = .top
rootSnapshotView = snapshotView
snapshotView.layer.cornerRadius = self.cornerRadius
snapshotView.layer.masksToBounds = true
@@ -227,7 +236,7 @@ class SPStorkPresentationController: UIPresentationController, UIGestureRecogniz
let snapshotRoundedView = UIView()
snapshotRoundedView.layer.cornerRadius = self.cornerRadius
snapshotRoundedView.layer.masksToBounds = true
snapshotRoundedView.backgroundColor = UIColor.black.withAlphaComponent(1 - self.alpha)
snapshotRoundedView.backgroundColor = UIColor.black.withAlphaComponent(self.alpha)
containerView.insertSubview(snapshotRoundedView, aboveSubview: snapshotView)
snapshotRoundedView.frame = initialFrame
snapshotRoundedView.transform = initialTransform
@@ -263,7 +272,7 @@ class SPStorkPresentationController: UIPresentationController, UIGestureRecogniz
extension SPStorkPresentationController {
@objc func handlePan(gestureRecognizer: UIPanGestureRecognizer) {
guard gestureRecognizer.isEqual(pan), self.isSwipeToDismissEnabled else { return }
guard gestureRecognizer.isEqual(self.pan), self.swipeToDismissEnabled else { return }
switch gestureRecognizer.state {
case .began:
@@ -275,7 +284,7 @@ extension SPStorkPresentationController {
gestureRecognizer.setTranslation(CGPoint(x: 0, y: 0), in: containerView)
case .changed:
self.workGester = true
if self.isSwipeToDismissEnabled {
if self.swipeToDismissEnabled {
let translation = gestureRecognizer.translation(in: presentedView)
self.updatePresentedViewForTranslation(inVerticalDirection: translation.y)
} else {
@@ -284,8 +293,8 @@ extension SPStorkPresentationController {
case .ended:
self.workGester = false
let translation = gestureRecognizer.translation(in: presentedView).y
if translation >= 240 {
presentedViewController.dismiss(animated: true, completion: nil)
if translation >= self.translateForDismiss {
self.presentedViewController.dismiss(animated: true, completion: nil)
} else {
self.indicatorView.style = .arrow
UIView.animate(
@@ -316,6 +325,10 @@ extension SPStorkPresentationController {
self.updateSnapshot()
}
func setIndicator(style: SPStorkIndicatorView.Style) {
self.indicatorView.style = style
}
private func updatePresentedViewForTranslation(inVerticalDirection translation: CGFloat) {
if self.startDismissing { return }
@@ -25,15 +25,14 @@ final class SPStorkPresentingAnimationController: NSObject, UIViewControllerAnim
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
guard let presentedViewController = transitionContext.viewController(forKey: .to) else {
return
}
guard let presentedViewController = transitionContext.viewController(forKey: .to) else { return }
let containerView = transitionContext.containerView
containerView.addSubview(presentedViewController.view)
presentedViewController.view.frame = CGRect(x: 0, y: containerView.bounds.height, width: containerView.bounds.width, height: containerView.bounds.height)
let finalFrameForPresentedView = transitionContext.finalFrame(for: presentedViewController)
presentedViewController.view.frame = finalFrameForPresentedView
presentedViewController.view.frame.origin.y = containerView.bounds.height
UIView.animate(
withDuration: transitionDuration(using: transitionContext),
@@ -23,19 +23,21 @@ import UIKit
public final class SPStorkTransitioningDelegate: NSObject, UIViewControllerTransitioningDelegate {
public var isSwipeToDismissEnabled: Bool = true
public var isTapAroundToDismissEnabled: Bool = true
public var swipeToDismissEnabled: Bool = true
public var tapAroundToDismissEnabled: Bool = true
public var showIndicator: Bool = true
public var indicatorColor: UIColor = UIColor.init(red: 202/255, green: 201/255, blue: 207/255, alpha: 1)
public var customHeight: CGFloat? = nil
public var translateForDismiss: CGFloat = 240
public func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
let controller = SPStorkPresentationController(presentedViewController: presented, presenting: presenting)
controller.isSwipeToDismissEnabled = self.isSwipeToDismissEnabled
controller.isTapAroundToDismissEnabled = self.isTapAroundToDismissEnabled
controller.swipeToDismissEnabled = self.swipeToDismissEnabled
controller.tapAroundToDismissEnabled = self.tapAroundToDismissEnabled
controller.showIndicator = self.showIndicator
controller.indicatorColor = self.indicatorColor
controller.customHeight = self.customHeight
controller.translateForDismiss = self.translateForDismiss
controller.transitioningDelegate = self
return controller
}
@@ -0,0 +1,40 @@
// The MIT License (MIT)
// Copyright © 2017 Ivan Vorobei (hello@ivanvorobei.by)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
import UIKit
extension UIViewController {
public var isPresentedAsStork: Bool {
return transitioningDelegate is SPStorkTransitioningDelegate
&& modalPresentationStyle == .custom
&& presentingViewController != nil
}
public func presentAsStork(_ controller: UIViewController, height: CGFloat? = nil, complection: (() -> Void)? = nil) {
let transitionDelegate = SPStorkTransitioningDelegate()
transitionDelegate.customHeight = height
controller.transitioningDelegate = transitionDelegate
controller.modalPresentationStyle = .custom
controller.modalPresentationCapturesStatusBarAppearance = true
self.present(controller, animated: true, completion: complection)
}
}
@@ -23,7 +23,7 @@ import UIKit
public class SPAnimation {
static func animate(_ duration: TimeInterval,
public static func animate(_ duration: TimeInterval,
animations: (() -> Void)!,
delay: TimeInterval = 0,
options: UIView.AnimationOptions = [],
@@ -40,14 +40,14 @@ public class SPAnimation {
})
}
static func animateWithRepeatition(_ duration: TimeInterval,
public static func animateWithRepeatition(_ duration: TimeInterval,
animations: (() -> Void)!,
delay: TimeInterval = 0,
options: UIView.AnimationOptions = [],
withComplection completion: (() -> Void)! = {}) {
var optionsWithRepeatition = options
optionsWithRepeatition.insert([.autoreverse, .repeat])
optionsWithRepeatition.insert([.autoreverse, .repeat, .allowUserInteraction])
self.animate(
duration,
@@ -23,11 +23,11 @@ import UIKit
public class SPAnimationAlpha {
fileprivate static let durationListAnimation: TimeInterval = 0.45
fileprivate static let coefLenthForTransition: CGFloat = 2.8
fileprivate static let delayPerItem: TimeInterval = 0.09
public static let durationListAnimation: TimeInterval = 0.45
public static let coefLenthForTransition: CGFloat = 2.8
public static let delayPerItem: TimeInterval = 0.09
static func hideList(_ duration: TimeInterval = durationListAnimation,
public static func hideList(_ duration: TimeInterval = durationListAnimation,
views: [UIView],
delayPerItem: TimeInterval = delayPerItem,
withComplection completion: (() -> Void)! = {}) {
@@ -51,7 +51,7 @@ public class SPAnimationAlpha {
}
}
static func hideReverseList(_ duration: TimeInterval = durationListAnimation,
public static func hideReverseList(_ duration: TimeInterval = durationListAnimation,
views: [UIView],
delayPerItem: TimeInterval = delayPerItem,
withComplection completion: (() -> Void)! = {}) {
@@ -76,7 +76,7 @@ public class SPAnimationAlpha {
}
}
static func showList(_ duration: TimeInterval = durationListAnimation,
public static func showList(_ duration: TimeInterval = durationListAnimation,
views: [UIView],
delayPerItem: TimeInterval = delayPerItem,
withComplection completion: (() -> Void)! = {}) {
@@ -23,10 +23,10 @@ import UIKit
public class SPAnimationSpring {
fileprivate static let spring: CGFloat = 1
fileprivate static let velocity: CGFloat = 1
public static let spring: CGFloat = 1
public static let velocity: CGFloat = 1
static func animate(_ duration: TimeInterval,
public static func animate(_ duration: TimeInterval,
animations: (() -> Void)!,
delay: TimeInterval = 0,
spring: CGFloat = spring,
@@ -47,7 +47,7 @@ public class SPAnimationSpring {
})
}
static func animateWithRepeatition(_ duration: TimeInterval,
public static func animateWithRepeatition(_ duration: TimeInterval,
animations: (() -> Void)!,
delay: TimeInterval = 0,
spring: CGFloat = spring,
@@ -23,11 +23,11 @@ import UIKit
public class SPAnimationUpward {
fileprivate static let durationListAnimation: TimeInterval = 0.45
fileprivate static let coefLenthForTransition: CGFloat = 2.8
fileprivate static let delayPerItem: TimeInterval = 0.09
public static let durationListAnimation: TimeInterval = 0.45
public static let coefLenthForTransition: CGFloat = 2.8
public static let delayPerItem: TimeInterval = 0.09
static func hide(_ duration: TimeInterval,
public static func hide(_ duration: TimeInterval,
view: UIView,
delay: TimeInterval = 0,
withComplection completion: (() -> Void)! = {}) {
@@ -48,7 +48,7 @@ public class SPAnimationUpward {
})
}
static func hideList(_ duration: TimeInterval = durationListAnimation,
public static func hideList(_ duration: TimeInterval = durationListAnimation,
views: [UIView],
delayPerItem: TimeInterval = delayPerItem,
withComplection completion: (() -> Void)! = {}) {
@@ -69,7 +69,7 @@ public class SPAnimationUpward {
}
static func show(_ duration: TimeInterval,
public static func show(_ duration: TimeInterval,
view: UIView,
delay: TimeInterval = 0,
withComplection completion: (() -> Void)! = {}) {
@@ -93,7 +93,7 @@ public class SPAnimationUpward {
})
}
static func showList(_ duration: TimeInterval = durationListAnimation,
public static func showList(_ duration: TimeInterval = durationListAnimation,
views: [UIView],
delayPerItem: TimeInterval = delayPerItem,
options: UIView.AnimationOptions = [],
@@ -24,19 +24,27 @@ import StoreKit
struct SPApp {
static var udid: String? {
public static var udid: String? {
return UIDevice.current.identifierForVendor?.uuidString
}
static var displayName: String? {
public static var displayName: String? {
return Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String
}
static var rootController: UIViewController? {
public static var rootController: UIViewController? {
return UIApplication.shared.keyWindow?.rootViewController
}
static func set(rootController: UIViewController, animatable: Bool = true) {
public static var safeArea: UIEdgeInsets {
if #available(iOS 11.0, *) {
return UIApplication.shared.keyWindow?.safeArea ?? UIEdgeInsets.zero
} else {
return UIEdgeInsets.zero
}
}
public static func set(rootController: UIViewController, animatable: Bool = true) {
rootController.view.frame = UIScreen.main.bounds
@@ -57,7 +65,7 @@ struct SPApp {
}
}
static func set(elementsColor: UIColor) {
public static func set(elementsColor: UIColor) {
UINavigationController.elementsColor = elementsColor
UIAlertController.elementsColor = elementsColor
UITabBarController.elementsColor = elementsColor
@@ -25,7 +25,7 @@ extension SPApp {
public struct Badge {
static var number: Int {
public static var number: Int {
get {
return UIApplication.shared.applicationIconBadgeNumber
}
@@ -34,7 +34,7 @@ extension SPApp {
}
}
static func reset() {
public static func reset() {
UIApplication.shared.applicationIconBadgeNumber = 0
}
@@ -23,13 +23,13 @@ import UIKit
extension SPApp {
struct Launch {
public struct Launch {
static func run() {
public static func run() {
self.count += 1
}
static var count: Int {
public static var count: Int {
get {
return UserDefaults.standard.value(forKey: "SPLaunchCount") as? Int ?? 0
}
@@ -38,7 +38,7 @@ extension SPApp {
}
}
static var isFirstLaunch: Bool {
public static var isFirstLaunch: Bool {
return (self.count == 1) || (self.count == 0)
}
@@ -24,7 +24,7 @@ import SafariServices
extension SPApp {
static func open(app: SPSystemApp) {
public static func open(app: SPSystemApp) {
switch app {
case SPSystemApp.photos:
guard let settingsUrl = URL(string: "photos-redirect://") else {
@@ -63,7 +63,7 @@ extension SPApp {
}
}
static func open(link: String, redirect: Bool) {
public static func open(link: String, redirect: Bool) {
guard let url = URL(string: link) else {
print("SPOpener - can not create URL")
@@ -24,12 +24,12 @@ import StoreKit
struct SPAppStore {
static func link(appID: String) -> String {
public static func link(appID: String) -> String {
return "https://itunes.apple.com/by/app/id" + appID
}
static func open(appID: String) {
if let url = URL(string: "itms-apps://itunes.apple.com/app/id\(appID)"),
public static func open(app id: String) {
if let url = URL(string: "itms-apps://itunes.apple.com/app/id\(id)"),
UIApplication.shared.canOpenURL(url) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: convertToUIApplicationOpenExternalURLOptionsKeyDictionary([:]), completionHandler: nil)
@@ -39,7 +39,7 @@ struct SPAppStore {
}
}
static func requestReview(appID: String, force: Bool) {
public static func requestReview(appID: String, force: Bool) {
if force {
if let url = URL(string: "itms-apps://itunes.apple.com/us/app/apple-store/id\(appID)?mt=8&action=write-review"),
UIApplication.shared.canOpenURL(url) {
@@ -56,13 +56,13 @@ struct SPAppStore {
}
}
static func requestReview() {
public static func requestReview() {
if #available(iOS 10.3, *) {
SKStoreReviewController.requestReview()
}
}
static func isUpdateAvailable(completion: @escaping (Bool)->()) {
public static func isUpdateAvailable(completion: @escaping (Bool)->()) {
guard let info = Bundle.main.infoDictionary,
let currentVersion = info["CFBundleShortVersionString"] as? String,
@@ -24,12 +24,12 @@ import AVFoundation
public struct SPAudio {
static func notStopBackgroundMusic() {
public static func notStopBackgroundMusic() {
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category(rawValue: convertFromAVAudioSessionCategory(AVAudioSession.Category.ambient)), mode: AVAudioSession.Mode.default)
try AVAudioSession.sharedInstance().setActive(true)
} catch {
print("SPAudio - notStopBackgroundMusic, error")
}
}
@@ -27,7 +27,7 @@ public class SPAudioPlayer: NSObject, AVAudioPlayerDelegate {
fileprivate var player: AVAudioPlayer = AVAudioPlayer()
fileprivate var endPlayingComplection: (()->())? = nil
func play(fileName: String, complection: (()->())? = nil) {
public func play(fileName: String, complection: (()->())? = nil) {
self.endPlayingComplection?()
self.player = AVAudioPlayer()
let url = Bundle.main.url(forResource: fileName, withExtension: nil)
@@ -47,7 +47,7 @@ public class SPAudioPlayer: NSObject, AVAudioPlayerDelegate {
}
}
func stop() {
public func stop() {
player.stop()
}
@@ -23,7 +23,7 @@ import UIKit
struct SPBufer {
static var text: String? {
public static var text: String? {
get {
return UIPasteboard.general.string
}
@@ -21,4 +21,4 @@
import UIKit
struct SPCodeDraw { private init() {} }
public struct SPCodeDraw { private init() {} }
@@ -23,7 +23,7 @@ import UIKit
public struct SPConstraints {
static func setEqualSizeSuperview(for view: UIView) {
public static func setEqualSizeSuperview(for view: UIView) {
if let superView = view.superview {
view.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
@@ -21,7 +21,7 @@
import Foundation
public func delay(_ delay:Double, closure:@escaping ()->()) {
public func delay(_ delay:Double, closure: @escaping ()->()) {
let when = DispatchTime.now() + delay
DispatchQueue.main.asyncAfter(deadline: when) {
closure()
@@ -21,19 +21,19 @@
import UIKit
struct SPDevice {
public struct SPDevice {
static var iphone: Bool {
public static var iphone: Bool {
return UIDevice.current.userInterfaceIdiom == .phone
}
static var ipad: Bool {
public static var ipad: Bool {
return UIDevice.current.userInterfaceIdiom == .pad
}
struct Orientation {
public struct Orientation {
static var isPortrait: Bool {
public static var isPortrait: Bool {
var isPortraitOrientation = true
if UIDevice.current.orientation.isValidInterfaceOrientation {
if UIDevice.current.orientation.isPortrait {
@@ -23,7 +23,7 @@ import UIKit
struct SPDownloader {
static func image(link: String, withComplection complection: @escaping (UIImage?) -> ()) {
public static func image(link: String, withComplection complection: @escaping (UIImage?) -> ()) {
guard let url = URL(string: link) else {
DispatchQueue.main.async {
complection(nil)
@@ -23,7 +23,7 @@ import Foundation
extension Array {
func get(count: Int) -> Array {
public func get(count: Int) -> Array {
if (count < self.count) { return Array(self[0..<count]) }
return Array(self)
}
@@ -31,7 +31,7 @@ extension Array {
extension Array where Element: Equatable {
mutating func removeDuplicates() {
public mutating func removeDuplicates() {
var result = [Element]()
for value in self {
if result.contains(value) == false { result.append(value) }
@@ -42,7 +42,7 @@ extension Array where Element: Equatable {
extension Array where Element: Hashable {
func after(item: Element) -> Element? {
public func after(item: Element) -> Element? {
if let index = self.index(of: item), index + 1 < self.count { return self[index + 1] }
return nil
}
@@ -23,17 +23,29 @@ import UIKit
extension CGRect {
var bottomXPosition: CGFloat {
public var bottomX: CGFloat {
get { return self.origin.x + self.width }
set { self.origin.x = newValue - self.width }
}
var bottomYPosition: CGFloat {
public var bottomY: CGFloat {
get { return self.origin.y + self.height }
set { self.origin.y = newValue - self.height }
}
var minSideSize: CGFloat {
public var minSide: CGFloat {
return min(self.width, self.height)
}
public mutating func set(width: CGFloat) {
self = CGRect.init(x: self.origin.x, y: self.origin.y, width: width, height: self.height)
}
public mutating func set(height: CGFloat) {
self = CGRect.init(x: self.origin.x, y: self.origin.y, width: self.width, height: height)
}
public mutating func set(width: CGFloat, height: CGFloat) {
self = CGRect.init(x: self.origin.x, y: self.origin.y, width: width, height: height)
}
}
@@ -23,13 +23,13 @@ import UIKit
extension CGSize {
func resize(width: CGFloat) -> CGSize {
public func resize(width: CGFloat) -> CGSize {
let relativeSideSize = self.width / self.height
let newHeight = width / relativeSideSize
return CGSize.init(width: width, height: newHeight)
}
func resize(height: CGFloat) -> CGSize {
public func resize(height: CGFloat) -> CGSize {
let relativeSideSize = self.width / self.height
let newWidth = height * relativeSideSize
return CGSize.init(width: newWidth, height: height)
@@ -23,13 +23,13 @@ import Foundation
extension Date {
func format(mask: String) -> String {
public func format(mask: String) -> String {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = mask
return dateFormatter.string(from: self)
}
static func create(from value: String) -> Date? {
public static func create(from value: String) -> Date? {
let formatter = DateFormatter()
formatter.dateFormat = "dd.MM.yyyy HH:mm"
let date = formatter.date(from: value)
@@ -24,57 +24,65 @@ import UIKit
extension String {
var digits: String {
public var digits: String {
return components(separatedBy: CharacterSet.decimalDigits.inverted).joined()
}
mutating func dropLast(substring: String) {
public mutating func dropLast(substring: String) {
if self.hasSuffix(substring) {
self = String(dropLast(substring.count))
}
}
mutating func dropFirst(substring: String) {
public mutating func dropFirst(substring: String) {
if self.hasPrefix(substring) {
self = String(dropFirst(substring.count))
}
}
func uppercasedFirstLetter() -> String {
public func uppercasedFirstLetter() -> String {
let lowercaseSctring = self.lowercased()
return lowercaseSctring.prefix(1).uppercased() + lowercaseSctring.dropFirst()
}
mutating func uppercaseFirstLetter() {
public mutating func uppercaseFirstLetter() {
self = self.uppercasedFirstLetter()
}
func removeAllSpaces() -> String {
public func removeAllSpaces() -> String {
return self.components(separatedBy: .whitespaces).joined()
}
mutating func removeAllSpaces() {
public mutating func removeAllSpaces() {
self = self.removeAllSpaces()
}
var isEmail: Bool {
public var isEmail: Bool {
let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}"
let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx)
return emailTest.evaluate(with: self)
}
var isLink: Bool {
public var isLink: Bool {
if let url = URL(string: self) {
return UIApplication.shared.canOpenURL(url)
}
return false
}
mutating func replace(_ replacingString: String, with newString: String) {
public var isEmpty: Bool {
return (self.removeAllSpaces() == "")
}
public var words: [String] {
return components(separatedBy: .punctuationCharacters).joined().components(separatedBy: .whitespaces)
}
public mutating func replace(_ replacingString: String, with newString: String) {
self = self.replacingOccurrences(of: replacingString, with: newString)
}
func replace(_ replacingString: String, with newString: String) -> String {
public func replace(_ replacingString: String, with newString: String) -> String {
return self.replacingOccurrences(of: replacingString, with: newString)
}
}
@@ -23,7 +23,7 @@ import UIKit
extension UITextField {
@IBInspectable var placeholderColor: UIColor? {
@IBInspectable public var placeholderColor: UIColor? {
get {
return self.placeholderColor
}
@@ -23,7 +23,7 @@ import UIKit
extension UIAlertController {
static var elementsColor: UIColor {
public static var elementsColor: UIColor {
get {
return UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor
}
@@ -39,13 +39,12 @@ extension UIAlertController {
preferredStyle: .alert
)
if cancelButtonTitle != nil {
ac.addAction(UIAlertAction.init(
title: cancelButtonTitle!,
style: UIAlertAction.Style.cancel,
handler: nil)
)
}
guard cancelButtonTitle != nil else { return }
ac.addAction(UIAlertAction.init(
title: cancelButtonTitle!,
style: UIAlertAction.Style.cancel,
handler: nil)
)
ac.addAction(UIAlertAction.init(
title: buttonTitle,
@@ -64,10 +63,8 @@ extension UIAlertController {
preferredStyle: .actionSheet
)
var style = UIAlertAction.Style.default
if isDestructive {
style = .destructive
}
let style = isDestructive ? .destructive : UIAlertAction.Style.default
ac.addAction(UIAlertAction.init(
title: buttonTitle,
style: style,
@@ -76,28 +73,34 @@ extension UIAlertController {
}))
ac.addAction(UIAlertAction.init(
title: cancelButtonTitle,
style: UIAlertAction.Style.default,
style: UIAlertAction.Style.cancel,
handler: { (action) in
complection(false)
}))
viewController.present(ac, animated: true, completion: nil)
}
}
extension UIAlertController {
func addAction(title: String, complection: @escaping ()->()) {
public func addAction(title: String, complection: @escaping ()->()) {
let action = UIAlertAction(title: title, style: .default) { (action) in
complection()
}
self.addAction(action)
}
func addDestructiveAction(title: String, complection: @escaping ()->()) {
public func addDestructiveAction(title: String, complection: @escaping ()->()) {
let action = UIAlertAction(title: title, style: .destructive) { (action) in
complection()
}
self.addAction(action)
}
public func addCancelAction(title: String, complection: @escaping ()->() = {}) {
let action = UIAlertAction(title: title, style: .cancel) { (action) in
complection()
}
self.addAction(action)
}
}
@@ -23,7 +23,7 @@ import UIKit
extension UIButton {
typealias UIButtonTargetClosure = () -> ()
public typealias UIButtonTargetClosure = () -> ()
private class ClosureWrapper: NSObject {
let closure: UIButtonTargetClosure
@@ -47,7 +47,7 @@ extension UIButton {
}
}
func target(_ action: @escaping UIButtonTargetClosure) {
public func target(_ action: @escaping UIButtonTargetClosure) {
targetClosure = action
addTarget(self, action: #selector(UIButton.targetAction), for: .touchUpInside)
}
@@ -60,20 +60,28 @@ extension UIButton {
extension UIButton {
func setTitle(_ title: String) {
public func setTitle(_ title: String, color: UIColor? = nil) {
self.setTitle(title, for: .normal)
if let color = color {
self.setTitleColor(color)
}
}
func setTitleColor(_ color: UIColor) {
public func setTitleColor(_ color: UIColor) {
self.setTitleColor(color, for: .normal)
self.setTitleColor(color.withAlphaComponent(0.7), for: .highlighted)
}
func removeAllTargets() {
public func setImage(_ image: UIImage) {
self.setImage(image, for: .normal)
self.imageView?.contentMode = .scaleAspectFit
}
public func removeAllTargets() {
self.removeTarget(nil, action: nil, for: .allEvents)
}
func showText(_ text: String, withComplection completion: (() -> Void)! = {}) {
public func showText(_ text: String, withComplection completion: (() -> Void)! = {}) {
let baseText = self.titleLabel?.text ?? " "
SPAnimation.animate(0.2, animations: {
self.titleLabel?.alpha = 0
@@ -97,7 +105,7 @@ extension UIButton {
})
}
func setAnimatableText(_ text: String, withComplection completion: (() -> Void)! = {}) {
public func setAnimatableText(_ text: String, withComplection completion: (() -> Void)! = {}) {
SPAnimation.animate(0.3, animations: {
self.titleLabel?.alpha = 0
}, withComplection: {
@@ -110,16 +118,16 @@ extension UIButton {
})
}
func hideContent(completion: (() -> Void)! = {}) {
SPAnimation.animate(0.2, animations: {
public func hideContent(completion: (() -> Void)! = {}) {
SPAnimation.animate(0.25, animations: {
self.titleLabel?.alpha = 0
}, withComplection: {
completion()
})
}
func showContent(completion: (() -> Void)! = {}) {
SPAnimation.animate(0.2, animations: {
public func showContent(completion: (() -> Void)! = {}) {
SPAnimation.animate(0.25, animations: {
self.titleLabel?.alpha = 1
}, withComplection: {
completion()
@@ -23,7 +23,7 @@ import UIKit
extension UICollectionView {
var currentIndexCellPath: IndexPath? {
public var currentIndexCellPath: IndexPath? {
let visibleRect = CGRect(origin: self.contentOffset, size: self.bounds.size)
let visiblePoint = CGPoint.init(x: visibleRect.midX, y: visibleRect.midY)
let visibleIndexPath = self.indexPathForItem(at: visiblePoint)
@@ -23,7 +23,7 @@ import UIKit
public extension UIColor {
convenience init(hex: String) {
public convenience init(hex: String) {
var red: CGFloat = 0.0
var green: CGFloat = 0.0
var blue: CGFloat = 0.0
@@ -23,40 +23,39 @@ import UIKit
public extension UIFont {
public static func system(type: BoldType, size: CGFloat) -> UIFont {
return UIFont.systemFont(ofSize: size, weight: self.getBoldTypeBy(boldType: type))
public static func system(weight: FontWeight, size: CGFloat) -> UIFont {
return UIFont.systemFont(ofSize: size, weight: self.weight(for: weight))
}
@available(iOS 8.2, *)
private static func getBoldTypeBy(boldType: BoldType) -> UIFont.Weight {
switch boldType {
case .UltraLight:
private static func weight(for weight: FontWeight) -> UIFont.Weight {
switch weight {
case .ultraLight:
return UIFont.Weight.ultraLight
case .Light:
case .light:
return UIFont.Weight.light
case .Medium:
case .medium:
return UIFont.Weight.medium
case .Regular:
case .regular:
return UIFont.Weight.regular
case .Bold:
case .bold:
return UIFont.Weight.bold
case .DemiBold:
case .demiBold:
return UIFont.Weight.semibold
case .Heavy:
case .heavy:
return UIFont.Weight.heavy
default:
return UIFont.Weight.regular
}
}
public enum BoldType {
case Regular
case Medium
case Light
case UltraLight
case Heavy
case Bold
case DemiBold
case None
public enum FontWeight {
case regular
case medium
case light
case ultraLight
case heavy
case bold
case demiBold
case none
}
}
@@ -32,4 +32,12 @@ public extension UIImage {
UIGraphicsEndImageContext()
return newImage!
}
var alwaysOriginal: UIImage {
return self.withRenderingMode(.alwaysOriginal)
}
var alwaysTemplate: UIImage {
return self.withRenderingMode(.alwaysTemplate)
}
}
@@ -23,7 +23,7 @@ import UIKit
public extension UILabel {
func setShadowOffsetForLetters(blurRadius: CGFloat = 0, widthOffset: CGFloat = 0, heightOffset: CGFloat, opacity: CGFloat) {
public func setShadowOffsetForLetters(blurRadius: CGFloat = 0, widthOffset: CGFloat = 0, heightOffset: CGFloat, opacity: CGFloat) {
self.layer.shadowRadius = blurRadius
self.layer.shadowOffset = CGSize(
width: widthOffset,
@@ -32,29 +32,29 @@ public extension UILabel {
self.layer.shadowOpacity = Float(opacity)
}
func setShadowOffsetFactorForLetters(blurRadius: CGFloat = 0, widthOffsetFactor: CGFloat = 0, heightOffsetFactor: CGFloat, opacity: CGFloat) {
public func setShadowOffsetFactorForLetters(blurRadius: CGFloat = 0, widthOffsetFactor: CGFloat = 0, heightOffsetFactor: CGFloat, opacity: CGFloat) {
let widthOffset = widthOffsetFactor * self.frame.width
let heightOffset = heightOffsetFactor * self.frame.height
self.setShadowOffsetForLetters(blurRadius: blurRadius, widthOffset: widthOffset, heightOffset: heightOffset, opacity: opacity)
}
func removeShadowForLetters() {
public func removeShadowForLetters() {
self.setShadowOffsetForLetters(blurRadius: 0, widthOffset: 0, heightOffset: 0, opacity: 0)
}
func setCenteringAlignment() {
public func setCenterAlignment() {
self.textAlignment = .center
self.baselineAdjustment = .alignCenters
}
func setLettersSpacing(_ value: CGFloat) {
public func setLettersSpacing(_ value: CGFloat) {
if let textString = text {
let attrs: [NSAttributedString.Key : Any] = [.kern: value]
attributedText = NSAttributedString(string: textString, attributes: attrs)
}
}
func setLineSpacing(lineSpacing: CGFloat = 0.0, lineHeightMultiple: CGFloat = 0.0) {
public func setLineSpacing(_ lineSpacing: CGFloat = 0.0, lineHeightMultiple: CGFloat = 0.0) {
guard let labelText = self.text else { return }
@@ -71,7 +71,6 @@ public extension UILabel {
attributedString.addAttribute(NSAttributedString.Key.paragraphStyle, value:paragraphStyle, range:NSMakeRange(0, attributedString.length))
self.attributedText = attributedString
}
}
@@ -23,7 +23,7 @@ import UIKit
extension UINavigationController {
static var elementsColor: UIColor {
public static var elementsColor: UIColor {
get {
if UINavigationBar.appearance().tintColor != nil {
return UINavigationBar.appearance().tintColor
@@ -23,7 +23,7 @@ import UIKit
extension UITabBarController {
static var elementsColor: UIColor {
public static var elementsColor: UIColor {
get {
if UITabBar.appearance().tintColor != nil {
return UITabBar.appearance().tintColor
@@ -36,7 +36,7 @@ extension UITabBarController {
}
}
func addTabBarItem(title: String, image: UIImage, selectedImage: UIImage? = nil, controller: UIViewController) {
public func addTabBarItem(title: String, image: UIImage, selectedImage: UIImage? = nil, controller: UIViewController) {
let tabBarItem = UITabBarItem(
title: title,
@@ -23,19 +23,19 @@ import UIKit
extension UITableView {
var isEmpty: Bool {
public var isEmpty: Bool {
return self.lastSectionWithRows == nil
}
func isEmpty(section: Int) -> Bool {
public func isEmpty(section: Int) -> Bool {
return self.numberOfRows(inSection: section) == 0
}
var lastSection: Int {
public var lastSection: Int {
return self.numberOfSections - 1
}
var lastSectionWithRows: Int? {
public var lastSectionWithRows: Int? {
if self.numberOfSections == 0 { return nil }
var section = self.numberOfSections - 1
if section < 0 { return nil }
@@ -46,7 +46,7 @@ extension UITableView {
return nil
}
var firstSectionWithRows: Int? {
public var firstSectionWithRows: Int? {
if self.numberOfSections == 0 { return nil }
var section = 0
if section > self.numberOfSections - 1 { return nil }
@@ -27,7 +27,7 @@ extension UITableViewCell {
return subviews.compactMap { $0 as? UIButton }.first
}
var highlightedColor: UIColor? {
public var highlightedColor: UIColor? {
get {
return self.backgroundView?.backgroundColor
}
@@ -23,7 +23,7 @@ import UIKit
extension UITextField {
var isEmptyText: Bool {
public var isEmptyText: Bool {
get {
if self.text == "" {
return true
@@ -90,7 +90,7 @@ extension UIViewController {
}
}
@objc func image(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {
@objc public func image(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {
if let _ = error {
self.imageSaved(isSuccses: false)
} else {
@@ -98,14 +98,14 @@ extension UIViewController {
}
}
@objc func imageSaved(isSuccses: Bool) {
@objc public func imageSaved(isSuccses: Bool) {
fatalError("SPUIViewControllerExtenshion - Need ovveride 'imageSaved' func")
}
}
extension UIViewController {
func setPrefersLargeNavigationTitle(_ title: String, smallScreenToSmallBar: Bool = true) {
public func setPrefersLargeNavigationTitle(_ title: String, smallScreenToSmallBar: Bool = true) {
self.navigationItem.title = title
if #available(iOS 11.0, *) {
self.navigationItem.largeTitleDisplayMode = .automatic
@@ -23,7 +23,7 @@ import UIKit
public extension UIView {
var viewController: UIViewController? {
public var viewController: UIViewController? {
get {
if let nextResponder = self.next as? UIViewController { return nextResponder }
else if let nextResponder = self.next as? UIView { return nextResponder.viewController }
@@ -34,7 +34,7 @@ public extension UIView {
public extension UIView {
var safeArea: UIEdgeInsets {
public var safeArea: UIEdgeInsets {
if #available(iOS 11.0, *) {
return self.safeAreaInsets
} else{
@@ -42,24 +42,11 @@ public extension UIView {
}
}
func set(width: CGFloat, height: CGFloat) {
self.setHeight(height)
self.setWidth(width)
public func setBounds(_ view: UIView, withWidthFactor widthFactor: CGFloat = 1, maxWidth: CGFloat? = nil, withHeightFactor heightFactor: CGFloat = 1, maxHeight: CGFloat? = nil, withCentering: Bool = false) {
self.setBounds(view.bounds, withWidthFactor: widthFactor, maxWidth: maxWidth, withHeightFactor: heightFactor, maxHeight: maxHeight, withCentering: withCentering)
}
func setHeight(_ height: CGFloat) {
self.frame = CGRect.init(x: self.frame.origin.x, y: self.frame.origin.y, width: self.frame.width, height: height)
}
func setWidth(_ width: CGFloat) {
self.frame = CGRect.init(x: self.frame.origin.x, y: self.frame.origin.y, width: width, height: self.frame.height)
}
func setEqualsFrameFromBounds(_ view: UIView, withWidthFactor widthFactor: CGFloat = 1, maxWidth: CGFloat? = nil, withHeightFactor heightFactor: CGFloat = 1, maxHeight: CGFloat? = nil, withCentering: Bool = false) {
self.setEqualsFrameFromBounds(view.bounds, withWidthFactor: widthFactor, maxWidth: maxWidth, withHeightFactor: heightFactor, maxHeight: maxHeight, withCentering: withCentering)
}
func setEqualsFrameFromBounds(_ bounds: CGRect, withWidthFactor widthFactor: CGFloat = 1, maxWidth: CGFloat? = nil, withHeightFactor heightFactor: CGFloat = 1, maxHeight: CGFloat? = nil, withCentering: Bool = false) {
public func setBounds(_ bounds: CGRect, withWidthFactor widthFactor: CGFloat = 1, maxWidth: CGFloat? = nil, withHeightFactor heightFactor: CGFloat = 1, maxHeight: CGFloat? = nil, withCentering: Bool = false) {
var width = bounds.width * widthFactor
if maxWidth != nil { width.setIfMore(when: maxWidth!) }
@@ -75,7 +62,7 @@ public extension UIView {
}
}
func setEqualsBoundsFromSuperview(customWidth: CGFloat? = nil, customHeight: CGFloat? = nil) {
public func setSuperviewBounds(customWidth: CGFloat? = nil, customHeight: CGFloat? = nil) {
if self.superview == nil { return }
self.frame = CGRect.init(origin: CGPoint.zero, size: self.superview!.frame.size)
if customWidth != nil {
@@ -86,7 +73,7 @@ public extension UIView {
}
}
func resize(width: CGFloat) {
public func resize(width: CGFloat) {
let relativeFactor = self.frame.width / self.frame.height
if relativeFactor.isNaN { return }
self.frame = CGRect.init(
@@ -97,7 +84,7 @@ public extension UIView {
)
}
func resize(height: CGFloat) {
public func resize(height: CGFloat) {
let relativeFactor = self.frame.width / self.frame.height
if relativeFactor.isNaN { return }
self.frame = CGRect.init(
@@ -108,27 +95,27 @@ public extension UIView {
)
}
func setYCenteringFromSuperview() {
public func setYCenter() {
self.center.y = (self.superview?.frame.height ?? 0) / 2
}
func setXCenteringFromSuperview() {
public func setXCenter() {
self.center.x = (self.superview?.frame.width ?? 0) / 2
}
func setToCenterInSuperview() {
public func setToCenter() {
self.center = CGPoint.init(x: ((self.superview?.frame.width) ?? 0) / 2, y: ((self.superview?.frame.height) ?? 0) / 2)
}
}
public extension UIView {
func setParalax(amountFactor: CGFloat) {
let amount = self.frame.minSideSize * amountFactor
public func setParalax(amountFactor: CGFloat) {
let amount = self.frame.minSide * amountFactor
self.setParalax(amount: amount)
}
func setParalax(amount: CGFloat) {
public func setParalax(amount: CGFloat) {
self.motionEffects.removeAll()
let horizontal = UIInterpolatingMotionEffect(keyPath: "center.x", type: .tiltAlongHorizontalAxis)
horizontal.minimumRelativeValue = -amount
@@ -146,7 +133,7 @@ public extension UIView {
public extension UIView {
func addGrade(alpha: CGFloat, color: UIColor = UIColor.black) -> UIView {
public func addGrade(alpha: CGFloat, color: UIColor = UIColor.black) -> UIView {
let gradeView = UIView.init()
gradeView.alpha = 0
self.addSubview(gradeView)
@@ -159,7 +146,7 @@ public extension UIView {
extension UIView {
func setShadow(
public func setShadow(
xTranslationFactor: CGFloat,
yTranslationFactor: CGFloat,
widthRelativeFactor: CGFloat,
@@ -174,14 +161,14 @@ extension UIView {
let xTranslation = (self.frame.width - shadowWidth) / 2 + (self.frame.width * xTranslationFactor)
let yTranslation = (self.frame.height - shadowHeight) / 2 + (self.frame.height * yTranslationFactor)
let cornerRadius = self.frame.minSideSize * cornerRadiusFactor
let cornerRadius = self.frame.minSide * cornerRadiusFactor
let shadowPath = UIBezierPath.init(
roundedRect: CGRect.init(x: xTranslation, y: yTranslation, width: shadowWidth, height: shadowHeight),
cornerRadius: cornerRadius
)
let blurRadius = self.frame.minSideSize * blurRadiusFactor
let blurRadius = self.frame.minSide * blurRadiusFactor
self.layer.shadowColor = UIColor.black.cgColor
self.layer.shadowOffset = CGSize.zero
@@ -191,7 +178,7 @@ extension UIView {
self.layer.shadowPath = shadowPath.cgPath;
}
func setShadow(
public func setShadow(
xTranslation: CGFloat,
yTranslation: CGFloat,
widthRelativeFactor: CGFloat,
@@ -216,14 +203,14 @@ extension UIView {
self.layer.shadowPath = shadowPath.cgPath
}
func removeShadow() {
public func removeShadow() {
self.layer.shadowColor = nil
self.layer.shadowOffset = CGSize.zero
self.layer.shadowOpacity = 0
self.layer.shadowPath = nil
}
func addShadowOpacityAnimation(to: CGFloat, duration: CFTimeInterval) {
public func addShadowOpacityAnimation(to: CGFloat, duration: CFTimeInterval) {
let animation = CABasicAnimation(keyPath:"shadowOpacity")
animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut)
animation.fromValue = self.layer.cornerRadius
@@ -237,7 +224,7 @@ extension UIView {
extension UIView {
func addCornerRadiusAnimation(to: CGFloat, duration: CFTimeInterval) {
public func addCornerRadiusAnimation(to: CGFloat, duration: CFTimeInterval) {
let animation = CABasicAnimation(keyPath:"cornerRadius")
animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut)
animation.fromValue = self.layer.cornerRadius
@@ -247,14 +234,14 @@ extension UIView {
self.layer.cornerRadius = to
}
func show(duration: TimeInterval = 0.3) {
public func show(duration: TimeInterval = 0.3) {
self.isHidden = false
SPAnimation.animate(duration, animations: {
self.alpha = 1
})
}
func hide(duration: TimeInterval = 0.3) {
public func hide(duration: TimeInterval = 0.3) {
SPAnimation.animate(duration, animations: {
self.alpha = 0
}, withComplection: {
@@ -262,21 +249,21 @@ extension UIView {
})
}
func removeAllAnimations() {
public func removeAllAnimations() {
self.layer.removeAllAnimations()
}
}
extension UIView {
func roundCorners(_ corners: UIRectCorner, radius: CGFloat) {
public func roundCorners(_ corners: UIRectCorner, radius: CGFloat) {
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.cgPath
self.layer.mask = mask
}
func round() {
self.layer.cornerRadius = self.frame.minSideSize / 2
public func round() {
self.layer.cornerRadius = self.frame.minSide / 2
}
}
@@ -23,12 +23,12 @@ import UIKit
extension UIVisualEffectView {
convenience init(style: UIBlurEffect.Style) {
public convenience init(style: UIBlurEffect.Style) {
let effect = UIBlurEffect(style: style)
self.init(effect: effect)
}
convenience init(vibrancy style: UIBlurEffect.Style) {
public convenience init(vibrancy style: UIBlurEffect.Style) {
let effect = UIBlurEffect(style: style)
let vibrancyEffect = UIVibrancyEffect(blurEffect: effect)
self.init(effect: vibrancyEffect)
@@ -23,15 +23,15 @@ import Foundation
extension UserDefaults {
func set(stringArray array: [String], forKey key: String) {
public func set(stringArray array: [String], forKey key: String) {
self.set(array, forKey: key)
}
func set(boolArray array: [Bool], forKey key: String) {
public func set(boolArray array: [Bool], forKey key: String) {
self.set(array, forKey: key)
}
func boolArray(forKey defaultName: String) -> [Bool] {
public func boolArray(forKey defaultName: String) -> [Bool] {
return UserDefaults.standard.array(forKey: defaultName) as? [Bool] ?? []
}
}
@@ -21,9 +21,9 @@
import UIKit
struct SPLayout {
public struct SPLayout {
static func sizeWith(widthFactor: CGFloat, maxWidth: CGFloat?, heightFactor: CGFloat, maxHeight: CGFloat?, relativeSideFactor: CGFloat?, from size: CGSize) -> CGSize {
public static func sizeWith(widthFactor: CGFloat, maxWidth: CGFloat?, heightFactor: CGFloat, maxHeight: CGFloat?, relativeSideFactor: CGFloat?, from size: CGSize) -> CGSize {
var widthArea = size.width * widthFactor
var heightArea = size.height * heightFactor
@@ -24,7 +24,7 @@ import LocalAuthentication
struct SPLocalAuthentication {
static var isEnable: Bool {
public static var isEnable: Bool {
let context = LAContext()
var error: NSError?
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
@@ -38,7 +38,7 @@ struct SPLocalAuthentication {
}
}
static func request(reason: String, complecton: @escaping (Bool)->()) {
public static func request(reason: String, complecton: @escaping (Bool)->()) {
let context = LAContext()
var error: NSError?
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
@@ -21,7 +21,7 @@
import UIKit
enum SPLocale: String, CaseIterable {
public enum SPLocale: String, CaseIterable {
case ru = "ru"
case en = "en"
@@ -24,11 +24,11 @@ import MessageUI
struct SPMail {
static var canSendEmail: Bool {
public static var canSendEmail: Bool {
return MFMailComposeViewController.canSendMail()
}
static func openApp(to email: String, subject: String? = nil, body: String? = nil) {
public static func openApp(to email: String, subject: String? = nil, body: String? = nil) {
let parametrs = "mailto:\(email)?subject=\(subject ?? "")&body=\(body ?? "")".addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)
if parametrs != nil {
@@ -40,7 +40,7 @@ struct SPMail {
}
}
static func dialog(to email: String, subject: String? = nil, body: String? = nil, on viewController: UIViewController) {
public static func dialog(to email: String, subject: String? = nil, body: String? = nil, on viewController: UIViewController) {
let mailVC = MFMailComposeViewController()
mailVC.mailComposeDelegate = SPMailSingltone.sharedInstance
@@ -21,21 +21,21 @@
import UIKit
enum SPNativeColors {
public enum SPNativeColors {
static let red = UIColor.init(hex: "FF3B30")
static let orange = UIColor.init(hex: "FF9500")
static let yellow = UIColor.init(hex: "FFCC00")
static let green = UIColor.init(hex: "4CD964")
static let tealBlue = UIColor.init(hex: "5AC8FA")
static let blue = UIColor.init(hex: "007AFF")
static let purple = UIColor.init(hex: "5856D6")
static let pink = UIColor.init(hex: "FF2D55")
static let white = UIColor.init(hex: "FFFFFF")
static let customGray = UIColor.init(hex: "EFEFF4")
static let lightGray = UIColor.init(hex: "E5E5EA")
static let lightGray2 = UIColor.init(hex: "D1D1D6")
static let midGray = UIColor.init(hex: "C7C7CC")
static let gray = UIColor.init(hex: "8E8E93")
static let black = UIColor.init(hex: "000000")
public static let red = UIColor.init(hex: "FF3B30")
public static let orange = UIColor.init(hex: "FF9500")
public static let yellow = UIColor.init(hex: "FFCC00")
public static let green = UIColor.init(hex: "4CD964")
public static let tealBlue = UIColor.init(hex: "5AC8FA")
public static let blue = UIColor.init(hex: "007AFF")
public static let purple = UIColor.init(hex: "5856D6")
public static let pink = UIColor.init(hex: "FF2D55")
public static let white = UIColor.init(hex: "FFFFFF")
public static let customGray = UIColor.init(hex: "EFEFF4")
public static let lightGray = UIColor.init(hex: "E5E5EA")
public static let lightGray2 = UIColor.init(hex: "D1D1D6")
public static let midGray = UIColor.init(hex: "C7C7CC")
public static let gray = UIColor.init(hex: "8E8E93")
public static let black = UIColor.init(hex: "000000")
}
@@ -22,9 +22,9 @@
import UIKit
import UserNotifications
struct SPLocalNotification {
public struct SPLocalNotification {
static func add(from timeInterval: TimeInterval, body: String, title: String? = nil, identifier: String? = nil) {
public static func add(from timeInterval: TimeInterval, body: String, title: String? = nil, identifier: String? = nil) {
let content = UNMutableNotificationContent()
content.body = body
@@ -50,8 +50,8 @@ struct SPLocalNotification {
}
}
static func add(in date: Date, body: String, title: String? = nil, identifier: String? = nil) {
public static func add(in date: Date, body: String, title: String? = nil, identifier: String? = nil) {
let content = UNMutableNotificationContent()
content.body = body
content.title = title ?? ""
@@ -77,7 +77,7 @@ struct SPLocalNotification {
}
}
static func remove(identifier: String) {
public static func remove(identifier: String) {
let center = UNUserNotificationCenter.current()
center.removePendingNotificationRequests(withIdentifiers: [identifier])
}
@@ -22,6 +22,7 @@
import UIKit
public extension String {
public static func random(count: Int) -> String {
let strings = [
"В доме кардинала от меня не было тайн; не раз видел я, как он усердно перелистывает старинные книги и жадно роется в пыли фамильных рукописей. Когда я как-то упрекнул его за бесполезные бессонные ночи, после которых он впадал в болезненное уныние, он взглянул на меня с горькой улыбкой и раскрыл передо мною историю города Рима. В этой книге, в двадцатой главе жизнеописания папы Александра Шестого, я прочел следующие строки, навсегда оставшиеся в моей памяти",
@@ -34,6 +35,7 @@ public extension String {
}
public extension Int {
public static func random(_ n: Int) -> Int {
return Int(arc4random_uniform(UInt32(n)))
}
@@ -44,6 +46,7 @@ public extension Int {
}
public extension Double {
public static func random() -> Double {
return Double(arc4random()) / 0xFFFFFFFF
}
@@ -54,6 +57,7 @@ public extension Double {
}
public extension Float {
public static func random() -> Float {
return Float(arc4random()) / 0xFFFFFFFF
}
@@ -64,6 +68,7 @@ public extension Float {
}
public extension CGFloat {
public static func random() -> CGFloat {
return CGFloat(Float(arc4random()) / 0xFFFFFFFF)
}
@@ -75,7 +80,7 @@ public extension CGFloat {
public extension Collection {
func shuffle() -> [Iterator.Element] {
public func shuffle() -> [Iterator.Element] {
var list = Array(self)
list.shuffleInPlace()
return list
@@ -84,7 +89,7 @@ public extension Collection {
extension Collection where Index == Int {
func random() -> Iterator.Element? {
public func random() -> Iterator.Element? {
return isEmpty ? nil : self[Int(arc4random_uniform(UInt32(endIndex)))]
}
}
@@ -21,4 +21,4 @@
import Foundation
struct SPShadow { private init() {} }
public struct SPShadow { private init() {} }
@@ -23,7 +23,7 @@ import UIKit
extension SPShadow {
struct DeepStyle {
public struct DeepStyle {
private init() {}
@@ -66,7 +66,7 @@ extension SPShadow {
yTranslation = view.frame.height + maxBottomSpace - shadowHeight
}
var blurRadius = view.frame.minSideSize * blurRadiusFactor
var blurRadius = view.frame.minSide * blurRadiusFactor
blurRadius.setIfMore(when: 10)
blurRadius.setIfFewer(when: 7)
@@ -85,14 +85,14 @@ extension SPShadow {
extension UIView {
func setDeepShadow() {
public func setDeepShadow() {
SPShadow.DeepStyle.setFor(view: self)
}
}
extension UILabel {
func setDeepShadowForLetters() {
public func setDeepShadowForLetters() {
SPShadow.DeepStyle.setFor(label: self)
}
}
@@ -25,7 +25,7 @@ public struct SPShare {
public struct Native {
static func share(text: String? = nil, fileNames: [String] = [], images: [UIImage] = [], complection: ((_ isSharing: Bool)->())? = nil, sourceView: UIView, on viewController: UIViewController) {
public static func share(text: String? = nil, fileNames: [String] = [], images: [UIImage] = [], complection: ((_ isSharing: Bool)->())? = nil, sourceView: UIView, on viewController: UIViewController) {
var shareData: [Any] = []
if text != nil {
@@ -21,13 +21,13 @@
import UIKit
class SPInstagram {
public class SPInstagram {
static var isSetApp: Bool {
public static var isSetApp: Bool {
return UIApplication.shared.canOpenURL(URL(string: "instagram://user?username=test")!)
}
static func openPost(id: String) {
public static func openPost(id: String) {
let instagramHooks = "instagram://media?id=\(id)"
let instagramUrl = URL(string: instagramHooks)
let safariURL = URL(string: "instagram.com/\(id)")!
@@ -38,7 +38,7 @@ class SPInstagram {
}
}
static func openUser(username: String) {
public static func openUser(username: String) {
let instagramHooks = "instagram://user?username=\(username)"
let instagramUrl = URL(string: instagramHooks)
let safariURL = URL(string: "https://instagram.com/\(username)")!
@@ -21,13 +21,13 @@
import UIKit
class SPTelegram {
public class SPTelegram {
static var isSetApp: Bool {
public static var isSetApp: Bool {
return UIApplication.shared.canOpenURL(URL(string: "tg://msg?text=test")!)
}
static func share(text: String, complection: @escaping (_ isOpened: Bool)->() = {_ in }) {
public static func share(text: String, complection: @escaping (_ isOpened: Bool)->() = {_ in }) {
let urlStringEncoded = text.addingPercentEncoding( withAllowedCharacters: .urlHostAllowed)
let urlOptional = URL(string: "tg://msg?text=\(urlStringEncoded ?? "")")
if let url = urlOptional {
@@ -41,12 +41,12 @@ class SPTelegram {
}
}
static func joinChannel(id: String) {
public static func joinChannel(id: String) {
let url = "https://t.me/joinchat/\(id)"
SPApp.open(link: url, redirect: true)
}
static func openBot(username: String) {
public static func openBot(username: String) {
var username = username
if username.first == "@" {
username.removeFirst()
@@ -21,13 +21,13 @@
import UIKit
class SPTwitter {
public class SPTwitter {
static var isSetApp: Bool {
public static var isSetApp: Bool {
return UIApplication.shared.canOpenURL(URL(string: "twitter://post?message=test")!)
}
static func share(text: String, complection: @escaping (_ isOpened: Bool)->() = {_ in }) {
public static func share(text: String, complection: @escaping (_ isOpened: Bool)->() = {_ in }) {
let urlStringEncoded = text.addingPercentEncoding( withAllowedCharacters: .urlHostAllowed)
let urlOptional = URL(string: "twitter://post?message=\(urlStringEncoded ?? "")")
if let url = urlOptional {
@@ -21,13 +21,13 @@
import UIKit
class SPViber {
public class SPViber {
static var isSetApp: Bool {
public static var isSetApp: Bool {
return UIApplication.shared.canOpenURL(URL(string: "viber://forward?text=test")!)
}
static func share(text: String, complection: @escaping (_ isOpened: Bool)->() = {_ in }) {
public static func share(text: String, complection: @escaping (_ isOpened: Bool)->() = {_ in }) {
let urlStringEncoded = text.addingPercentEncoding( withAllowedCharacters: .urlHostAllowed)
let urlOptional = URL(string: "viber://forward?text=\(urlStringEncoded ?? "")")
if let url = urlOptional {
@@ -21,13 +21,13 @@
import UIKit
class SPWhatsApp {
public class SPWhatsApp {
static var isSetApp: Bool {
public static var isSetApp: Bool {
return UIApplication.shared.canOpenURL(URL(string: "whatsapp://send?text=test")!)
}
static func share(text: String, complection: @escaping (_ isOpened: Bool)->() = {_ in }) {
public static func share(text: String, complection: @escaping (_ isOpened: Bool)->() = {_ in }) {
let urlStringEncoded = text.addingPercentEncoding( withAllowedCharacters: .urlHostAllowed)
let urlOptional = URL(string: "whatsapp://send?text=\(urlStringEncoded ?? "")")
if let url = urlOptional {
@@ -1,62 +0,0 @@
// The MIT License (MIT)
// Copyright © 2017 Ivan Vorobei (hello@ivanvorobei.by)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
import Foundation
import CoreSpotlight
import MobileCoreServices
struct SPSpotlight {
static let domainIdentifier = "by.ivanvorobei"
static func addItem(identifier: String, title: String, description: String, addedData: Date? = nil, keywords: [String] = []) {
if #available(iOS 9.0, *) {
let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeMessage as String)
attributeSet.title = title
attributeSet.contentDescription = description
attributeSet.keywords = keywords
if addedData != nil {
attributeSet.contentCreationDate = addedData!
}
let item = CSSearchableItem(uniqueIdentifier: "\(identifier)", domainIdentifier: SPSpotlight.domainIdentifier, attributeSet: attributeSet)
CSSearchableIndex.default().indexSearchableItems([item]) { error in
if let error = error {
print("SPSpotlight addItem error: \(error.localizedDescription)")
}
}
}
}
static func removeItem(identifier: String) {
if #available(iOS 9.0, *) {
CSSearchableIndex.default().deleteSearchableItems(withIdentifiers: ["\(identifier)"]) { error in
if let error = error {
print("SPSpotlight removeItem error: \(error.localizedDescription)")
}
}
}
}
private init() {}
}
@@ -26,7 +26,7 @@ public enum SPStatusBar {
case light
}
public enum SPSystemIconType {
public enum SPSystemIcon {
case share
case close
case favorite
@@ -21,7 +21,7 @@
import UIKit
class SPAppStoreActionButton: SPDownloadingButton {
public class SPAppStoreActionButton: SPDownloadingButton {
var style: Style = .base {
didSet {
@@ -32,28 +32,28 @@ class SPAppStoreActionButton: SPDownloadingButton {
switch self.style {
case .base:
self.backgroundColor = self.secondColor
self.titleLabel?.font = UIFont.system(type: .Bold, size: 14)
self.titleLabel?.font = UIFont.system(weight: .bold, size: 14)
self.contentEdgeInsets = UIEdgeInsets.init(top: 6, left: 15, bottom: 6, right: 15)
break
case .main:
self.backgroundColor = self.baseColor
self.layer.borderWidth = 0
self.setTitleColor(UIColor.white)
self.titleLabel?.font = UIFont.system(type: .Bold, size: 14)
self.titleLabel?.font = UIFont.system(weight: .bold, size: 14)
self.contentEdgeInsets = UIEdgeInsets.init(top: 6, left: 15, bottom: 6, right: 15)
break
case .buyInStore:
self.backgroundColor = self.baseColor
self.layer.borderWidth = 0
self.setTitleColor(UIColor.white)
self.titleLabel?.font = UIFont.system(type: .Bold, size: 14)
self.titleLabel?.font = UIFont.system(weight: .bold, size: 14)
self.contentEdgeInsets = UIEdgeInsets.init(top: 8, left: 15, bottom: 8, right: 15)
break
case .line:
self.backgroundColor = UIColor.clear
self.layer.borderWidth = 1
self.layer.borderColor = self.baseColor.cgColor
self.titleLabel?.font = UIFont.system(type: .Medium, size: 14)
self.titleLabel?.font = UIFont.system(weight: .medium, size: 14)
self.contentEdgeInsets = UIEdgeInsets.init(top: 6, left: 15, bottom: 6, right: 15)
break
}
@@ -78,7 +78,7 @@ class SPAppStoreActionButton: SPDownloadingButton {
self.layer.masksToBounds = true
}
override func setTitle(_ title: String?, for state: UIControl.State) {
override public func setTitle(_ title: String?, for state: UIControl.State) {
switch self.style {
case .base:
super.setTitle(title?.uppercased(), for: state)
@@ -91,7 +91,7 @@ class SPAppStoreActionButton: SPDownloadingButton {
}
}
override func layoutSubviews() {
override public func layoutSubviews() {
super.layoutSubviews()
if self.style == .buyInStore {
self.layer.cornerRadius = 12
@@ -21,7 +21,7 @@
import UIKit
class SPAppleMusicButton: SPButton {
public class SPAppleMusicButton: SPButton {
var type: SPSelectionType = .unselect {
didSet {
@@ -44,7 +44,7 @@ class SPAppleMusicButton: SPButton {
override func commonInit() {
super.commonInit()
self.layer.cornerRadius = 8
self.titleLabel?.font = UIFont.system(type: .DemiBold, size: 15)
self.titleLabel?.font = UIFont.system(weight: .demiBold, size: 15)
self.contentEdgeInsets = UIEdgeInsets.init(top: 12, left: 27, bottom: 12, right: 27)
self.type = .unselect
}
@@ -21,7 +21,7 @@
import UIKit
class SPAppleMusicSectionButtonsView: SPView {
public class SPAppleMusicSectionButtonsView: SPView {
let topSeparatorView = SPSeparatorView()
let bottomSeparatorView = SPSeparatorView()
@@ -64,30 +64,30 @@ class SPAppleMusicSectionButtonsView: SPView {
func layout(origin: CGPoint, width: CGFloat) {
self.frame.origin = origin
self.set(width: width, height: sectionHeight)
self.frame.set(width: width, height: sectionHeight)
self.layoutSubviews()
}
override func layoutSubviews() {
override public func layoutSubviews() {
super.layoutSubviews()
self.topSeparatorView.frame.origin = .zero
self.topSeparatorView.setWidth(self.frame.width)
self.topSeparatorView.frame.set(width: self.frame.width)
self.bottomSeparatorView.frame.origin.x = 0
self.bottomSeparatorView.frame.bottomYPosition = self.frame.height
self.bottomSeparatorView.setWidth(self.frame.width)
self.bottomSeparatorView.frame.bottomY = self.frame.height
self.bottomSeparatorView.frame.set(width: self.frame.width)
let buttonWidth = (self.frame.width - self.buttonsSpace) / 2
self.leftButton.sizeToFit()
self.leftButton.setWidth(buttonWidth)
self.leftButton.frame.set(width: buttonWidth)
self.leftButton.frame.origin.x = 0
self.leftButton.center.y = self.frame.height / 2
self.rightButton.sizeToFit()
self.rightButton.setWidth(buttonWidth)
self.rightButton.frame.bottomXPosition = self.frame.width
self.rightButton.frame.set(width: buttonWidth)
self.rightButton.frame.bottomX = self.frame.width
self.rightButton.center.y = self.frame.height / 2
}
}
@@ -23,7 +23,28 @@ import UIKit
public class SPButton: UIButton {
var gradientView: SPGradientView? {
override public func imageRect(forContentRect contentRect: CGRect) -> CGRect {
if self.title(for: .normal) != nil {
let inset: CGFloat = 6
let sideSize = self.frame.height - inset * 2
let titleFrame = self.titleRect(forContentRect: contentRect)
return CGRect.init(x: titleFrame.origin.x - sideSize - 6, y: 0, width: sideSize, height: self.frame.height)
} else {
return super.imageRect(forContentRect: contentRect)
}
}
override public var isHighlighted: Bool{
didSet {
if self.isHighlighted {
self.imageView?.alpha = 0.7
} else {
self.imageView?.alpha = 1
}
}
}
public var gradientView: SPGradientView? {
didSet {
self.gradientView?.isUserInteractionEnabled = false
if self.gradientView?.superview == nil {
@@ -34,7 +55,7 @@ public class SPButton: UIButton {
}
}
var round: Bool = false {
public var rounded: Bool = false {
didSet {
self.layoutSubviews()
}
@@ -50,13 +71,26 @@ public class SPButton: UIButton {
self.commonInit()
}
internal func commonInit() {}
internal func commonInit() {
self.adjustsImageWhenHighlighted = false
}
override public func layoutSubviews() {
super.layoutSubviews()
self.gradientView?.setEqualsBoundsFromSuperview()
if self.round {
self.gradientView?.setSuperviewBounds()
if self.rounded {
self.round()
}
}
public func set(enable: Bool, animatable: Bool) {
self.isEnabled = enable
if animatable {
SPAnimation.animate(0.3, animations: {
self.alpha = enable ? 1 : 0.6
})
} else {
self.alpha = enable ? 1 : 0.6
}
}
}
@@ -21,7 +21,7 @@
import UIKit
class SPDotButton: SPButton {
public class SPDotButton: SPButton {
var customSideSize: CGFloat = 26 {
didSet {
@@ -37,7 +37,7 @@ class SPDotButton: SPButton {
}
}
override var isHighlighted: Bool{
override public var isHighlighted: Bool{
didSet{
if isHighlighted{
UIView.animate(withDuration: 0.1, delay: 0.0, usingSpringWithDamping: 1, initialSpringVelocity: 1.0, options: [.curveEaseOut, .beginFromCurrentState], animations: {
@@ -69,14 +69,14 @@ class SPDotButton: SPButton {
}
}
override func sizeToFit() {
override public func sizeToFit() {
super.sizeToFit()
self.setWidth(self.customSideSize)
self.setHeight(self.customSideSize)
self.frame.set(width: self.customSideSize)
self.frame.set(height: self.customSideSize)
self.layoutSubviews()
}
override func layoutSubviews() {
override public func layoutSubviews() {
super.layoutSubviews()
let space: CGFloat = 2
@@ -87,9 +87,9 @@ class SPDotButton: SPButton {
var currentXPosition: CGFloat = insest
for dotView in self.dotsView {
dotView.setWidth(sideSize)
dotView.setHeight(sideSize)
dotView.setYCenteringFromSuperview()
dotView.frame.set(width: sideSize)
dotView.frame.set(height: sideSize)
dotView.setYCenter()
dotView.frame.origin.x = currentXPosition
dotView.round()
currentXPosition += (sideSize + space)
@@ -21,12 +21,11 @@
import UIKit
class SPDownloadingButton: SPButton {
public class SPDownloadingButton: SPButton {
let activityIndicatorView = UIActivityIndicatorView.init()
var isFrameRounded: Bool = false
func startLoading() {
public func startLoading() {
self.activityIndicatorView.alpha = 0
self.activityIndicatorView.isHidden = false
self.activityIndicatorView.startAnimating()
@@ -39,7 +38,10 @@ class SPDownloadingButton: SPButton {
})
}
func stopLoading() {
public func stopLoading(newText: String? = nil) {
if let newText = newText {
self.setTitle(newText)
}
SPAnimation.animate(0.2, animations: {
self.activityIndicatorView.alpha = 0
}, withComplection: {
@@ -50,13 +52,9 @@ class SPDownloadingButton: SPButton {
})
}
override func layoutSubviews() {
override public func layoutSubviews() {
super.layoutSubviews()
self.activityIndicatorView.center = CGPoint.init(x: self.frame.width / 2, y: self.frame.height / 2)
if self.isFrameRounded {
self.round()
}
}
}
@@ -21,9 +21,9 @@
import UIKit
class SPNativeLargeButton: SPDownloadingButton {
public class SPNativeLargeButton: SPDownloadingButton {
override var isHighlighted: Bool {
override public var isHighlighted: Bool {
didSet {
if self.gradientView == nil {
if isHighlighted {
@@ -42,9 +42,9 @@ class SPNativeLargeButton: SPDownloadingButton {
}
}
override func commonInit() {
override public func commonInit() {
super.commonInit()
self.titleLabel?.font = UIFont.system(type: UIFont.BoldType.DemiBold, size: 16)
self.titleLabel?.font = UIFont.system(weight: UIFont.FontWeight.demiBold, size: 16)
self.setTitleColor(UIColor.white)
self.backgroundColor = SPNativeColors.blue
self.layer.masksToBounds = true
@@ -52,19 +52,19 @@ class SPNativeLargeButton: SPDownloadingButton {
self.contentEdgeInsets = UIEdgeInsets.init(top: 15, left: 15, bottom: 15, right: 15)
}
override func sizeToFit() {
override public func sizeToFit() {
super.sizeToFit()
if let superview = self.superview {
let sideSpace: CGFloat = superview.frame.width * 0.112
var width = superview.frame.width - sideSpace * 2
width.setIfMore(when: 335)
self.setWidth(width)
self.frame.set(width: width)
}
}
override func layoutSubviews() {
override public func layoutSubviews() {
super.layoutSubviews()
self.gradientView?.setEqualsBoundsFromSuperview()
self.gradientView?.setSuperviewBounds()
self.gradientView?.layer.cornerRadius = self.layer.cornerRadius
self.gradientView?.gradientLayer.cornerRadius = self.layer.cornerRadius
}
@@ -21,7 +21,7 @@
import UIKit
class SPPlayCircleButton: UIButton {
public class SPPlayCircleButton: UIButton {
var audioState: AudioState = AudioState.play {
didSet {
@@ -60,9 +60,9 @@ class SPPlayCircleButton: UIButton {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
override public func layoutSubviews() {
super.layoutSubviews()
self.iconView.setEqualsFrameFromBounds(self, withWidthFactor: 0.45, withHeightFactor: 0.45, withCentering: true)
self.iconView.setBounds(self, withWidthFactor: 0.45, withHeightFactor: 0.45, withCentering: true)
self.round()
}
@@ -21,7 +21,7 @@
import UIKit
class SPSocialButton: UIButton {
public class SPSocialButton: UIButton {
let iconView = SPSocialIconView.init()
var widthIconFactor: CGFloat = 0.5
@@ -33,7 +33,7 @@ class SPSocialButton: UIButton {
}
}
override var isHighlighted: Bool {
override public var isHighlighted: Bool {
didSet {
if isHighlighted {
self.iconView.color = self.iconView.color.withAlphaComponent(0.7)
@@ -43,7 +43,7 @@ class SPSocialButton: UIButton {
}
}
override var isEnabled: Bool {
override public var isEnabled: Bool {
didSet {
if isEnabled {
self.alpha = 1
@@ -79,9 +79,9 @@ class SPSocialButton: UIButton {
self.iconView.color = SPNativeColors.white
}
override func layoutSubviews() {
override public func layoutSubviews() {
super.layoutSubviews()
self.iconView.setEqualsFrameFromBounds(self, withWidthFactor: self.widthIconFactor, withHeightFactor: self.heightIconFactor, withCentering: true)
self.iconView.setBounds(self, withWidthFactor: self.widthIconFactor, withHeightFactor: self.heightIconFactor, withCentering: true)
self.round()
}
}
@@ -21,15 +21,16 @@
import UIKit
class SPSystemIconButton: UIButton {
public class SPSystemIconButton: SPButton {
let iconView = SPSystemIconView.init()
var widthIconFactor: CGFloat = 1
var heightIconFactor: CGFloat = 1
var type: SPSystemIconType {
var icon: SPSystemIcon {
didSet {
self.iconView.type = self.type
self.iconView.icon = self.icon
}
}
@@ -39,7 +40,7 @@ class SPSystemIconButton: UIButton {
}
}
override var isHighlighted: Bool {
override public var isHighlighted: Bool {
didSet {
if isHighlighted {
self.iconView.color = self.color.withAlphaComponent(0.7)
@@ -49,17 +50,17 @@ class SPSystemIconButton: UIButton {
}
}
init() {
self.type = .share
super.init(frame: CGRect.zero)
override init() {
self.icon = .share
super.init()
self.commonInit()
}
init(type: SPSystemIconType) {
self.type = type
super.init(frame: CGRect.zero)
self.iconView.type = self.type
self.type = type
init(type: SPSystemIcon) {
self.icon = type
super.init()
self.iconView.icon = self.icon
self.icon = type
self.commonInit()
}
@@ -67,13 +68,14 @@ class SPSystemIconButton: UIButton {
fatalError("init(coder:) has not been implemented")
}
fileprivate func commonInit() {
override func commonInit() {
super.commonInit()
self.iconView.isUserInteractionEnabled = false
self.addSubview(self.iconView)
}
override func layoutSubviews() {
override public func layoutSubviews() {
super.layoutSubviews()
self.iconView.setEqualsFrameFromBounds(self, withWidthFactor: self.widthIconFactor, withHeightFactor: self.heightIconFactor, withCentering: true)
self.iconView.setBounds(self, withWidthFactor: self.widthIconFactor, withHeightFactor: self.heightIconFactor, withCentering: true)
}
}
@@ -23,7 +23,7 @@ import UIKit
class SPSystemIconView: UIView {
var type: SPSystemIconType {
var icon: SPSystemIcon {
didSet {
self.setNeedsDisplay()
}
@@ -36,13 +36,13 @@ class SPSystemIconView: UIView {
}
init() {
self.type = .share
self.icon = .share
super.init(frame: CGRect.zero)
self.commonInit()
}
init(type: SPSystemIconType) {
self.type = type
init(type: SPSystemIcon) {
self.icon = type
super.init(frame: CGRect.zero)
self.commonInit()
}
@@ -57,7 +57,7 @@ class SPSystemIconView: UIView {
override func draw(_ rect: CGRect) {
super.draw(rect)
switch type {
switch icon {
case .share:
SPCodeDraw.SystemIconPack.drawShare(frame: rect, resizing: .aspectFit, color: self.color)
break
@@ -21,7 +21,7 @@
import UIKit
class SPMengTransformCollectionViewCell: SPCollectionViewCell {
public class SPMengTransformCollectionViewCell: SPCollectionViewCell {
let backgroundImageView = SPDownloadingImageView()
let titleLabel = UILabel()
@@ -125,7 +125,7 @@ class SPMengTransformCollectionViewCell: SPCollectionViewCell {
self.titleLabel.text = ""
self.titleLabel.setDeepShadowForLetters()
self.titleLabel.translatesAutoresizingMaskIntoConstraints = false
self.titleLabel.font = UIFont.system(type: .DemiBold, size: 32)
self.titleLabel.font = UIFont.system(weight: .demiBold, size: 32)
self.titleLabel.textColor = UIColor.white
self.titleLabel.numberOfLines = 0
contentView.addSubview(self.titleLabel)
@@ -140,7 +140,7 @@ class SPMengTransformCollectionViewCell: SPCollectionViewCell {
self.subtitleLabel.text = ""
self.subtitleLabel.setDeepShadowForLetters()
self.subtitleLabel.translatesAutoresizingMaskIntoConstraints = false
self.subtitleLabel.font = UIFont.system(type: .Regular, size: 17)
self.subtitleLabel.font = UIFont.system(weight: .regular, size: 17)
self.subtitleLabel.textColor = UIColor.white
self.subtitleLabel.numberOfLines = 0
contentView.addSubview(self.subtitleLabel)
@@ -153,7 +153,7 @@ class SPMengTransformCollectionViewCell: SPCollectionViewCell {
contentView.bottomAnchor, constant: -20).isActive = true
}
override func prepareForReuse() {
override public func prepareForReuse() {
super.prepareForReuse()
self.backgroundImageView.image = nil
self.titleLabel.text = ""
@@ -23,7 +23,7 @@ import UIKit
public class SPCollectionView: UICollectionView {
var layout = SPCollectionViewLayout()
let layout = UICollectionViewFlowLayout()
private var cacheImages: [(link: String, image: UIImage)] = []
required public init?(coder aDecoder: NSCoder) {
@@ -31,29 +31,35 @@ public class SPCollectionView: UICollectionView {
commonInit()
}
init(frame: CGRect) {
super.init(frame: frame, collectionViewLayout: self.layout)
commonInit()
init() {
super.init(frame: .zero, collectionViewLayout: self.layout)
self.commonInit()
}
init() {
super.init(frame: CGRect.zero, collectionViewLayout: self.layout)
commonInit()
public override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
super.init(frame: frame, collectionViewLayout: self.layout)
self.commonInit()
}
internal func commonInit() {
self.layout.scrollDirection = .vertical
self.backgroundColor = UIColor.clear
self.collectionViewLayout = self.layout
self.decelerationRate = UIScrollView.DecelerationRate.fast
self.delaysContentTouches = false
self.isPagingEnabled = false
self.showsHorizontalScrollIndicator = false
self.showsVerticalScrollIndicator = false
}
func height(rows: Int) -> CGFloat {
return self.layout.itemSize.height * CGFloat(rows) + self.layout.minimumLineSpacing * CGFloat(rows - 1)
}
func width(columns: Int) -> CGFloat {
return self.layout.itemSize.width * CGFloat(columns) + self.layout.minimumInteritemSpacing * CGFloat(columns - 1)
}
}
//MARK: - cache
//MARK: - Cache
extension SPCollectionView {
func setCachedImage(link: String, indexPath: IndexPath, on imageView: SPDownloadingImageView, cell: SPCollectionViewCell) {
@@ -21,7 +21,7 @@
import UIKit
struct SPMengTransformCollectionData {
public struct SPMengTransformCollectionData {
var title: String
var subtitle: String
@@ -40,7 +40,7 @@ struct SPMengTransformCollectionData {
}
}
class SPMengTransformCollectionView: SPCollectionView {
public class SPMengTransformCollectionView: SPPageCollectionView {
var data: [SPMengTransformCollectionData] = []
var withParalax: Bool = true
@@ -73,11 +73,11 @@ class SPMengTransformCollectionView: SPCollectionView {
extension SPMengTransformCollectionView: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.data.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let data = self.data[indexPath.row]
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "sectionCell", for: indexPath) as! SPMengTransformCollectionViewCell
cell.currentIndexPath = indexPath
@@ -166,7 +166,7 @@ extension SPMengTransformCollectionView: UICollectionViewDataSource {
extension SPMengTransformCollectionView: UICollectionViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
public func scrollViewDidScroll(_ scrollView: UIScrollView) {
self.updateCells()
}
@@ -0,0 +1,92 @@
// The MIT License (MIT)
// Copyright © 2017 Ivan Vorobei (hello@ivanvorobei.by)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
import UIKit
public class SPPageCollectionView: UICollectionView {
var layout = SPCollectionViewLayout()
private var cacheImages: [(link: String, image: UIImage)] = []
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}
init(frame: CGRect) {
super.init(frame: frame, collectionViewLayout: self.layout)
commonInit()
}
init() {
super.init(frame: CGRect.zero, collectionViewLayout: self.layout)
commonInit()
}
internal func commonInit() {
self.layout.scrollDirection = .vertical
self.backgroundColor = UIColor.clear
self.collectionViewLayout = self.layout
self.decelerationRate = UIScrollView.DecelerationRate.fast
self.delaysContentTouches = false
self.isPagingEnabled = false
self.showsHorizontalScrollIndicator = false
self.showsVerticalScrollIndicator = false
}
}
//MARK: - cache
extension SPPageCollectionView {
func setCachedImage(link: String, indexPath: IndexPath, on imageView: SPDownloadingImageView, cell: SPCollectionViewCell) {
if let image = self.fromCahce(link: link) {
imageView.setImage(image: image, animatable: false)
} else {
SPDownloader.image(link: link) { (response) in
if let image = response {
if cell.currentIndexPath == indexPath {
imageView.setImage(image: image, animatable: true)
self.toCache(link: link, image: image)
}
}
}
}
}
func toCache(link: String, image: UIImage?) {
if image == nil {
return
}
if self.fromCahce(link: link) == nil {
self.cacheImages.append((link: link, image: image!))
}
}
func fromCahce(link: String) -> UIImage? {
let cachedData = self.cacheImages.first(where: {
$0.link == link
})
return cachedData?.image
}
}
@@ -23,12 +23,16 @@ import UIKit
public class SPController: SPStatusBarManagerController {
let emptyTitlesView = SPEmptyTitlesView(title: "No Data", subtitle: "No data or information")
let emptyTitlesView = SPEmptyLabelsView(title: "No Data", subtitle: "No data or information")
override public func viewDidLoad() {
super.viewDidLoad()
self.emptyTitlesView.isHidden = true
self.view.addSubview(self.emptyTitlesView)
}
public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
self.updateLayout(with: self.view.frame.size)
}
@@ -39,12 +43,6 @@ public class SPController: SPStatusBarManagerController {
}, completion: nil)
}
@available(iOS 11.0, *)
override public func viewLayoutMarginsDidChange() {
super.viewLayoutMarginsDidChange()
self.updateLayout(with: self.view.frame.size)
}
func updateLayout(with size: CGSize) {
self.emptyTitlesView.layout(centerY: size.height / 2)
}
@@ -21,7 +21,7 @@
import UIKit
class SPNativeTableController: SPTableController {
public class SPNativeTableController: SPTableController {
let labelTableViewCellIdentifier: String = "labelTableViewCellIdentifier"
let textFieldTableViewCellIdentifier: String = "textFieldTableViewCellIdentifier"
@@ -42,7 +42,7 @@ class SPNativeTableController: SPTableController {
private var autoSpaceHeight: CGFloat = 35
override func viewDidLoad() {
override public func viewDidLoad() {
super.viewDidLoad()
self.statusBar = .dark
@@ -77,27 +77,25 @@ class SPNativeTableController: SPTableController {
self.activityIndicatorView.stopAnimating()
self.activityIndicatorView.color = SPNativeColors.gray
self.view.addSubview(self.activityIndicatorView)
self.updateLayout(with: self.view.frame.size)
}
override func numberOfSections(in tableView: UITableView) -> Int {
override public func numberOfSections(in tableView: UITableView) -> Int {
return super.numberOfSections(in: tableView)
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
override public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return super.tableView(tableView, numberOfRowsInSection: section)
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
override public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
fatalError("SPNativeTableViewController - need ivveride cellForRowAt")
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
override public func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return nil
}
override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
override public func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
return nil
}
@@ -159,7 +157,7 @@ class SPNativeTableController: SPTableController {
//MARK: - manage selection
extension SPNativeTableController {
override func tableView(_ tableView: UITableView, shouldHighlightRowAt indexPath: IndexPath) -> Bool {
override public func tableView(_ tableView: UITableView, shouldHighlightRowAt indexPath: IndexPath) -> Bool {
if let _ = tableView.cellForRow(at: indexPath) as? SPFormFeaturedTitleTableViewCell {
return false
@@ -173,7 +171,7 @@ extension SPNativeTableController {
//MARK: - manage spaces
extension SPNativeTableController {
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
override public func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if section == 0 {
return self.showTopInsets ? super.tableView(tableView, viewForHeaderInSection: section) : nil
} else {
@@ -181,7 +179,7 @@ extension SPNativeTableController {
}
}
override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
override public func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
if section == self.tableView.lastSection {
return self.showBottomInsets ? super.tableView(tableView, viewForFooterInSection: section) : nil
} else {
@@ -189,7 +187,7 @@ extension SPNativeTableController {
}
}
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
override public func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
let firstSection = self.tableView.firstSectionWithRows
if section == firstSection {
if self.showTopInsets {
@@ -217,7 +215,7 @@ extension SPNativeTableController {
}
override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
override public func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
if section == self.tableView.lastSectionWithRows {
if self.showBottomInsets {
if self.autoBottomSpace {
@@ -21,7 +21,7 @@
import UIKit
class SPProposeController: SPController {
public class SPProposeController: SPController {
private let data: Data
internal let areaView = AreaView()
@@ -31,6 +31,10 @@ class SPProposeController: SPController {
return 0.5
}
private var gradeFactor: CGFloat {
return 0.6
}
private var space: CGFloat {
return 6
}
@@ -54,7 +58,7 @@ class SPProposeController: SPController {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
override public func viewDidLoad() {
super.viewDidLoad()
self.areaView.isHidden = true
@@ -75,11 +79,9 @@ class SPProposeController: SPController {
if let image = self.data.image {
self.areaView.imageView.setImage(image: image, animatable: false)
}
self.updateLayout(with: self.view.frame.size)
}
override func viewDidAppear(_ animated: Bool) {
override public func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if !self.isPresent {
self.present()
@@ -88,19 +90,18 @@ class SPProposeController: SPController {
}
private func present() {
SPVibration.impact(system: .warning)
SPVibration.impact(.warning)
self.areaView.frame.origin.y = self.view.frame.size.height
self.areaView.isHidden = false
SPAnimationSpring.animate(self.animationDuration, animations: {
self.view.backgroundColor = UIColor.black.withAlphaComponent(0.6)
self.view.backgroundColor = UIColor.black.withAlphaComponent(self.gradeFactor)
self.areaView.frame.origin.y = self.view.frame.size.height - self.areaView.frame.height - (self.bottomSafeArea / 2) - self.space
}, spring: 1,
velocity: 1,
options: .transitionCurlUp)
}
override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
override public func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
let hide = {
self.view.backgroundColor = UIColor.black.withAlphaComponent(0)
self.areaView.frame.origin.y = self.view.frame.size.height
@@ -128,10 +129,8 @@ class SPProposeController: SPController {
}
override func updateLayout(with size: CGSize) {
self.areaView.setWidth(size.width - (self.space * 2))
self.areaView.layoutSubviews()
self.areaView.sizeToFit()
self.areaView.frame.origin.x = self.space
super.updateLayout(with: size)
self.areaView.layout(origin: CGPoint.init(x: self.space, y: 0), width: size.width - (self.space * 2))
self.areaView.frame.origin.y = self.view.frame.size.height - self.areaView.frame.height - (self.bottomSafeArea / 2) - self.space
}
@@ -140,6 +139,7 @@ class SPProposeController: SPController {
let returnAreaViewToPoint = {
SPAnimationSpring.animate(self.animationDuration, animations: {
self.areaView.frame.origin.y = self.view.frame.size.height - self.areaView.frame.height - (self.bottomSafeArea / 2) - self.space
self.view.backgroundColor = UIColor.black.withAlphaComponent(self.gradeFactor)
}, spring: 1,
velocity: 1,
options: .transitionCurlDown,
@@ -156,6 +156,13 @@ class SPProposeController: SPController {
let translation = sender.translation(in: self.view)
self.areaView.center = CGPoint(x: areaView.center.x + 0, y: areaView.center.y + translation.y / 4)
sender.setTranslation(CGPoint.zero, in: self.view)
let baseY = self.view.frame.size.height - self.areaView.frame.height - (self.bottomSafeArea / 2) - self.space
let dem = -(baseY - self.areaView.frame.origin.y) / 6
var newGrade = self.gradeFactor - (dem / 100)
newGrade.setIfFewer(when: 0.2)
newGrade.setIfMore(when: self.gradeFactor + 0.05)
self.view.backgroundColor = UIColor.black.withAlphaComponent(newGrade)
case .ended:
returnAreaViewToPoint()
default:
@@ -179,10 +186,9 @@ class SPProposeController: SPController {
let subtitleLabel = UILabel()
let imageView = SPDownloadingImageView()
let button = SPNativeLargeButton()
let closeButton = SPSystemIconButton(type: SPSystemIconType.close)
let closeButton = SPSystemIconButton(type: SPSystemIcon.close)
var imageSideSize: CGFloat = 160
private let space: CGFloat = 36
init() {
@@ -191,18 +197,18 @@ class SPProposeController: SPController {
self.layer.masksToBounds = true
self.layer.cornerRadius = 34
self.titleLabel.font = UIFont.system(type: .Regular, size: 28)
self.titleLabel.font = UIFont.system(weight: .regular, size: 28)
self.titleLabel.textColor = UIColor.init(hex: "939393")
self.titleLabel.numberOfLines = 1
self.titleLabel.adjustsFontSizeToFitWidth = true
self.titleLabel.minimumScaleFactor = 0.5
self.titleLabel.setCenteringAlignment()
self.titleLabel.setCenterAlignment()
self.addSubview(self.titleLabel)
self.subtitleLabel.font = UIFont.system(type: .Regular, size: 16)
self.subtitleLabel.font = UIFont.system(weight: .regular, size: 16)
self.subtitleLabel.textColor = SPNativeColors.black
self.subtitleLabel.numberOfLines = 0
self.subtitleLabel.setCenteringAlignment()
self.subtitleLabel.setCenterAlignment()
self.addSubview(self.subtitleLabel)
self.imageView.gradeView.backgroundColor = UIColor.white
@@ -210,15 +216,16 @@ class SPProposeController: SPController {
self.imageView.layer.masksToBounds = true
self.addSubview(self.imageView)
self.button.titleLabel?.font = UIFont.system(type: UIFont.BoldType.Medium, size: 15)
self.button.titleLabel?.font = UIFont.system(weight: UIFont.FontWeight.medium, size: 15)
self.button.setTitleColor(SPNativeColors.black)
self.button.backgroundColor = UIColor.init(hex: "D4D3DB")
self.button.layer.cornerRadius = 13
self.button.backgroundColor = SPNativeColors.lightGray
self.addSubview(self.button)
self.closeButton.widthIconFactor = 0.4
self.closeButton.heightIconFactor = 0.4
self.closeButton.backgroundColor = UIColor.init(hex: "EFEFF4")
self.closeButton.color = UIColor.init(hex: "979797")
self.closeButton.backgroundColor = SPNativeColors.lightGray.withAlphaComponent(0.6)
self.closeButton.color = UIColor.init(hex: "979797")
self.addSubview(self.closeButton)
}
@@ -230,36 +237,40 @@ class SPProposeController: SPController {
super.layoutSubviews()
self.titleLabel.sizeToFit()
self.titleLabel.frame.origin.y = self.space * 0.8
self.titleLabel.setWidth(self.frame.width - self.space * 3)
self.titleLabel.setXCenteringFromSuperview()
self.titleLabel.frame.origin.y = self.space * 0.9
self.titleLabel.frame.set(width: self.frame.width - self.space * 3)
self.titleLabel.setXCenter()
self.subtitleLabel.sizeToFit()
self.subtitleLabel.frame.origin.y = self.titleLabel.frame.bottomYPosition + 8
self.subtitleLabel.setWidth(self.frame.width - self.space * 2)
self.subtitleLabel.setXCenteringFromSuperview()
self.subtitleLabel.frame.origin.y = self.titleLabel.frame.bottomY + 8
self.subtitleLabel.frame.set(width: self.frame.width - self.space * 2)
self.subtitleLabel.setXCenter()
self.imageView.frame = CGRect.init(
x: 0, y: self.subtitleLabel.frame.bottomYPosition + self.space / 2,
x: 0, y: self.subtitleLabel.frame.bottomY + self.space / 2,
width: self.imageSideSize,
height: self.imageSideSize
)
self.imageView.setXCenteringFromSuperview()
self.imageView.setXCenter()
self.button.sizeToFit()
self.button.setWidth(self.frame.width - self.space * 2)
self.button.frame.origin.y = self.imageView.frame.bottomYPosition + self.space / 2
self.button.setXCenteringFromSuperview()
self.button.frame.set(height: 52)
self.button.frame.set(width: self.frame.width - self.space * 2)
self.button.frame.origin.y = self.imageView.frame.bottomY + self.space / 1.8
self.button.setXCenter()
self.closeButton.frame = CGRect.init(x: 0, y: 0, width: 24, height: 24)
self.closeButton.frame.origin.x = self.frame.width - self.closeButton.frame.width - 20
self.closeButton.frame.origin.y = 20
self.closeButton.round()
self.frame.set(height: self.button.frame.bottomY + self.space)
}
override func sizeToFit() {
super.sizeToFit()
self.setHeight(self.button.frame.bottomYPosition + self.space)
func layout(origin: CGPoint, width: CGFloat) {
self.frame.origin = origin
self.frame.set(width: width)
self.layoutSubviews()
}
}
@@ -21,33 +21,30 @@
import UIKit
class SPTableController: SPStatusBarManagerTableController {
public class SPTableController: SPStatusBarManagerTableController {
var activityIndicatorView = UIActivityIndicatorView.init()
override func viewDidLoad() {
override public func viewDidLoad() {
super.viewDidLoad()
self.activityIndicatorView.stopAnimating()
self.activityIndicatorView.color = SPNativeColors.gray
self.view.addSubview(self.activityIndicatorView)
}
public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
self.updateLayout(with: self.view.frame.size)
}
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
override public func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
coordinator.animate(alongsideTransition: { (contex) in
self.updateLayout(with: size)
}, completion: nil)
}
@available(iOS 11.0, *)
override func viewLayoutMarginsDidChange() {
super.viewLayoutMarginsDidChange()
self.updateLayout(with: self.view.frame.size)
}
func updateLayout(with size: CGSize) {
self.activityIndicatorView.center = CGPoint.init(
x: size.width / 2,
@@ -0,0 +1,67 @@
// The MIT License (MIT)
// Copyright © 2017 Ivan Vorobei (hello@ivanvorobei.by)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
import UIKit
public class SPCenterLabelsView: SPView {
let titleLabel = SPLabel()
let subtitleLabel = SPLabel()
override func commonInit() {
super.commonInit()
self.titleLabel.font = UIFont.system(weight: .bold, size: 33)
self.titleLabel.textAlignment = .center
self.titleLabel.textColor = UIColor.black
self.titleLabel.numberOfLines = 0
self.addSubview(self.titleLabel)
self.subtitleLabel.font = UIFont.system(weight: .regular, size: 17)
self.subtitleLabel.textAlignment = .center
self.subtitleLabel.textColor = UIColor.black
self.subtitleLabel.numberOfLines = 0
self.addSubview(self.subtitleLabel)
}
func layout(x: CGFloat, y: CGFloat, width: CGFloat) {
self.frame.origin = CGPoint.init(x: x, y: y)
self.frame.set(width: width)
self.layoutSubviews()
}
override public func layoutSubviews() {
super.layoutSubviews()
self.titleLabel.frame.set(width: self.frame.width)
self.titleLabel.sizeToFit()
self.titleLabel.frame.set(width: self.frame.width)
self.titleLabel.frame.origin = CGPoint.zero
self.subtitleLabel.frame.set(width: self.frame.width)
self.subtitleLabel.sizeToFit()
self.subtitleLabel.frame.set(width: self.frame.width)
self.subtitleLabel.frame.origin.x = 0
self.subtitleLabel.frame.origin.y = self.titleLabel.frame.bottomY + 7
self.frame.set(height: self.subtitleLabel.frame.bottomY)
}
}
@@ -21,7 +21,7 @@
import UIKit
class SPEmptyTitlesView: SPView {
class SPEmptyLabelsView: SPView {
let titleLabel = UILabel()
let subtitleLabel = UILabel()
@@ -39,22 +39,22 @@ class SPEmptyTitlesView: SPView {
override func commonInit() {
super.commonInit()
self.titleLabel.font = UIFont.system(type: .Bold, size: 29)
self.titleLabel.font = UIFont.system(weight: .bold, size: 29)
self.titleLabel.textColor = SPNativeColors.gray
self.titleLabel.setCenteringAlignment()
self.titleLabel.setCenterAlignment()
self.titleLabel.numberOfLines = 0
self.addSubview(self.titleLabel)
self.subtitleLabel.font = UIFont.system(type: .Regular, size: 17)
self.subtitleLabel.font = UIFont.system(weight: .regular, size: 17)
self.subtitleLabel.textColor = SPNativeColors.gray
self.subtitleLabel.setCenteringAlignment()
self.subtitleLabel.setCenterAlignment()
self.subtitleLabel.numberOfLines = 0
self.addSubview(self.subtitleLabel)
}
func layout(centerY: CGFloat) {
if let superview = self.superview {
self.setWidth(superview.frame.width * 0.7)
self.frame.set(width: superview.frame.width * 0.7)
self.layoutSubviews()
self.center = CGPoint.init(x: superview.frame.width / 2, y: centerY)
}
@@ -65,12 +65,12 @@ class SPEmptyTitlesView: SPView {
self.titleLabel.frame.origin = .zero
self.titleLabel.sizeToFit()
self.titleLabel.setWidth(self.frame.width)
self.titleLabel.frame.set(width: self.frame.width)
self.subtitleLabel.frame.origin = CGPoint.init(x: 0, y: self.titleLabel.frame.bottomYPosition + 5)
self.subtitleLabel.frame.origin = CGPoint.init(x: 0, y: self.titleLabel.frame.bottomY + 5)
self.subtitleLabel.sizeToFit()
self.subtitleLabel.setWidth(self.frame.width)
self.subtitleLabel.frame.set(width: self.frame.width)
self.setHeight(self.subtitleLabel.frame.bottomYPosition)
self.frame.set(height: self.subtitleLabel.frame.bottomY)
}
}
@@ -21,7 +21,7 @@
import UIKit
class SPSectionLabelsView: SPView {
public class SPSectionLabelsView: SPView {
let titleLabel = SPLabel()
let subtitleLabel = SPLabel()
@@ -30,48 +30,49 @@ class SPSectionLabelsView: SPView {
override func commonInit() {
super.commonInit()
self.titleLabel.font = UIFont.system(type: .Bold, size: 23)
self.titleLabel.font = UIFont.system(weight: .bold, size: 23)
self.titleLabel.textAlignment = .left
self.titleLabel.textColor = UIColor.black
self.titleLabel.numberOfLines = 0
self.addSubview(self.titleLabel)
self.subtitleLabel.font = UIFont.system(type: .Regular, size: 17)
self.subtitleLabel.font = UIFont.system(weight: .regular, size: 17)
self.subtitleLabel.textAlignment = .left
self.subtitleLabel.textColor = UIColor.black.withAlphaComponent(0.7)
self.subtitleLabel.numberOfLines = 0
self.addSubview(self.subtitleLabel)
self.button.titleLabel?.font = UIFont.system(type: .Regular, size: 17)
self.button.titleLabel?.font = UIFont.system(weight: .regular, size: 17)
self.button.setTitleColor(SPNativeColors.blue, for: UIControl.State.normal)
self.addSubview(self.button)
}
func layout(origin: CGPoint, width: CGFloat) {
self.frame.origin = origin
self.setWidth(width)
self.frame.set(width: width)
self.layoutSubviews()
}
override func layoutSubviews() {
func layout(x: CGFloat, y: CGFloat, width: CGFloat) {
self.layout(origin: CGPoint.init(x: x, y: y), width: width)
}
override public func layoutSubviews() {
super.layoutSubviews()
self.titleLabel.sizeToFit()
self.titleLabel.setWidth(self.frame.width)
self.titleLabel.frame.set(width: self.frame.width)
self.titleLabel.frame.origin = CGPoint.zero
//self.titleLabel.backgroundColor = UIColor.lightGray
self.subtitleLabel.sizeToFit()
self.subtitleLabel.setWidth(self.frame.width)
self.subtitleLabel.frame.set(width: self.frame.width)
self.subtitleLabel.frame.origin.x = 0
self.subtitleLabel.frame.origin.y = self.titleLabel.frame.bottomYPosition + 3
//self.subtitleLabel.backgroundColor = UIColor.darkGray
self.subtitleLabel.frame.origin.y = self.titleLabel.frame.bottomY + 3
self.button.sizeToFit()
self.button.frame.bottomXPosition = self.frame.width
self.button.frame.bottomX = self.frame.width
self.button.center.y = self.titleLabel.center.y
//self.button.backgroundColor = UIColor.darkGray
self.setHeight(self.subtitleLabel.frame.bottomYPosition)
self.frame.set(height: self.subtitleLabel.frame.bottomY)
}
}
@@ -21,7 +21,7 @@
import UIKit
class SPDownloadingImageView: SPImageView {
public class SPDownloadingImageView: SPImageView {
let activityIndiactorView = UIActivityIndicatorView.init()
let gradeView = UIView.init()
@@ -33,7 +33,7 @@ class SPDownloadingImageView: SPImageView {
self.addSubview(self.gradeView)
self.gradeView.backgroundColor = UIColor.init(hex: "F0F1F6")
self.activityIndiactorView.color = UIColor.darkGray
self.addSubview(self.activityIndiactorView)
//self.addSubview(self.activityIndiactorView)
self.activityIndiactorView.startAnimating()
}
@@ -68,9 +68,9 @@ class SPDownloadingImageView: SPImageView {
self.gradeView.alpha = 1
}
override func layoutSubviews() {
override public func layoutSubviews() {
super.layoutSubviews()
self.gradeView.setEqualsBoundsFromSuperview()
self.gradeView.setSuperviewBounds()
self.activityIndiactorView.center = CGPoint.init(x: self.bounds.midX, y: self.bounds.midY)
}
}
@@ -23,7 +23,7 @@ import UIKit
public class SPFakeBarView: UIView {
public var style: SPNavigationTitleStyle = . small {
public var style: SPNavigationTitleStyle = .small {
didSet {
self.updateStyle()
}
@@ -54,15 +54,15 @@ public class SPFakeBarView: UIView {
}
}
public var closeButton: closeButtonPlace = .none {
public var closeButtonPossition: CloseButtonPosition = .none {
didSet {
self.leftButton.titleLabel?.font = UIFont.system(type: .Regular, size: 17)
self.rightButton.titleLabel?.font = UIFont.system(type: .Regular, size: 17)
switch self.closeButton {
self.leftButton.titleLabel?.font = UIFont.system(weight: .regular, size: 17)
self.rightButton.titleLabel?.font = UIFont.system(weight: .regular, size: 17)
switch self.closeButtonPossition {
case .left:
self.leftButton.titleLabel?.font = UIFont.system(type: .DemiBold, size: 17)
self.leftButton.titleLabel?.font = UIFont.system(weight: .demiBold, size: 17)
case .right:
self.rightButton.titleLabel?.font = UIFont.system(type: .DemiBold, size: 17)
self.rightButton.titleLabel?.font = UIFont.system(weight: .demiBold, size: 17)
case .none:
break
}
@@ -121,7 +121,7 @@ public class SPFakeBarView: UIView {
self.addSubview(self.subtitleLabel)
self.subtitleLabel.textColor = UIColor.init(hex: "8E8E92")
self.subtitleLabel.font = UIFont.system(type: .DemiBold, size: 13)
self.subtitleLabel.font = UIFont.system(weight: .demiBold, size: 13)
self.subtitleLabel.translatesAutoresizingMaskIntoConstraints = false
self.subtitleLabel.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: 16).isActive = true
self.subtitleLabel.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -16).isActive = true
@@ -129,7 +129,7 @@ public class SPFakeBarView: UIView {
self.leftButton.setTitleColor(self.elementsColor)
self.leftButton.titleLabel?.textAlignment = .left
self.leftButton.titleLabel?.font = UIFont.system(type: .DemiBold, size: 16)
self.leftButton.titleLabel?.font = UIFont.system(weight: .demiBold, size: 16)
self.leftButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: 17, bottom: 0, right: 0)
self.addSubview(self.leftButton)
self.leftButton.translatesAutoresizingMaskIntoConstraints = false
@@ -138,14 +138,14 @@ public class SPFakeBarView: UIView {
self.rightButton.setTitleColor(self.elementsColor)
self.rightButton.titleLabel?.textAlignment = .right
self.rightButton.titleLabel?.font = UIFont.system(type: .DemiBold, size: 17)
self.rightButton.titleLabel?.font = UIFont.system(weight: .demiBold, size: 17)
self.rightButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 16)
self.addSubview(self.rightButton)
self.rightButton.translatesAutoresizingMaskIntoConstraints = false
self.rightButton.trailingAnchor.constraint(equalTo: self.trailingAnchor).isActive = true
self.rightButton.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: -12).isActive = true
self.closeButton = .none
self.closeButtonPossition = .none
self.setContraints()
self.updateStyle()
@@ -185,14 +185,14 @@ public class SPFakeBarView: UIView {
self.titleBottomConstraint?.constant = -12
}
self.addStatusBarHeight = true
self.titleLabel.font = UIFont.system(type: .DemiBold, size: 17)
self.titleLabel.setCenteringAlignment()
self.titleLabel.font = UIFont.system(weight: .demiBold, size: 17)
self.titleLabel.setCenterAlignment()
case .stork:
self.height = 66
self.titleBottomConstraint?.constant = -12
self.addStatusBarHeight = false
self.titleLabel.font = UIFont.system(type: .DemiBold, size: 17)
self.titleLabel.setCenteringAlignment()
self.titleLabel.font = UIFont.system(weight: .demiBold, size: 17)
self.titleLabel.setCenterAlignment()
case .large:
if UIViewController.statusBarHeight == 44 {
self.height = 140 - 44
@@ -202,7 +202,7 @@ public class SPFakeBarView: UIView {
self.titleBottomConstraint?.constant = -4
}
self.addStatusBarHeight = true
self.titleLabel.font = UIFont.system(type: .Bold, size: 34)
self.titleLabel.font = UIFont.system(weight: .bold, size: 34)
self.titleLabel.textAlignment = .left
break
}
@@ -215,7 +215,7 @@ public class SPFakeBarView: UIView {
self.updateConstraints()
}
public enum closeButtonPlace {
public enum CloseButtonPosition {
case left
case right
case none
@@ -21,7 +21,7 @@
import UIKit
class SPFooterActionsView: SPView {
public class SPFooterActionsView: SPView {
var sectionLabels = SPSectionLabelsView()
private var buttons: [SPFooterActionButton] = []
@@ -36,8 +36,7 @@ class SPFooterActionsView: SPView {
func addButton(title: String, titleColor: UIColor, target: @escaping ()->()) {
let button = SPFooterActionButton()
button.setTitle(title)
button.setTitleColor(titleColor)
button.setTitle(title, color: titleColor)
button.target { target() }
self.buttons.append(button)
self.addSubview(button)
@@ -47,19 +46,26 @@ class SPFooterActionsView: SPView {
self.addSubview(separator)
}
func button(for id: Int) -> SPFooterActionButton? {
if (self.buttons.count - 1) < id {
return nil
}
return self.buttons[id]
}
func layout(origin: CGPoint, width: CGFloat) {
self.frame.origin = origin
self.setWidth(width)
self.frame.set(width: width)
self.layoutSubviews()
}
override func layoutSubviews() {
override public func layoutSubviews() {
super.layoutSubviews()
self.sectionLabels.layout(origin: CGPoint.zero, width: self.frame.width)
let buttonHeight: CGFloat = 50
var yPositionButton: CGFloat = self.sectionLabels.frame.bottomYPosition + 12
var yPositionButton: CGFloat = self.sectionLabels.frame.bottomY + 12
if !self.buttons.isEmpty {
for i in 0...(buttons.count - 1) {
@@ -68,24 +74,44 @@ class SPFooterActionsView: SPView {
separator.frame.origin.x = 0
separator.frame.origin.y = yPositionButton
separator.setWidth(self.frame.width)
separator.frame.set(width: self.frame.width)
button.frame = CGRect.init(x: 0, y: yPositionButton, width: self.frame.width, height: buttonHeight)
yPositionButton += buttonHeight
}
self.setHeight(yPositionButton)
self.frame.set(height: yPositionButton)
}
}
}
class SPFooterActionButton: SPButton {
var rightIconView: UIView? {
willSet {
self.rightIconView?.removeFromSuperview()
}
didSet {
if let view = self.rightIconView {
self.addSubview(view)
self.layoutSubviews()
}
}
}
override func commonInit() {
super.commonInit()
self.setTitleColor(SPNativeColors.blue)
self.titleLabel?.font = UIFont.system(type: .Regular, size: 21)
self.titleLabel?.font = UIFont.system(weight: .regular, size: 21)
self.contentHorizontalAlignment = .left
}
override func layoutSubviews() {
super.layoutSubviews()
let sideSize: CGFloat = self.frame.height * 0.36
self.rightIconView?.frame = CGRect.init(x: 0, y: 0, width: sideSize, height: sideSize)
self.rightIconView?.center.y = self.frame.height / 2
self.rightIconView?.frame.bottomX = self.frame.width - sideSize / 3
}
}
@@ -21,7 +21,7 @@
import UIKit
class SPGradeBlurView: UIView {
public class SPGradeBlurView: UIView {
internal var gradeView: UIView = UIView()
internal var blurView: UIView = UIView()
@@ -67,7 +67,7 @@ class SPGradeBlurView: UIView {
self.setBlurRadius(blurRaius)
}
override func layoutSubviews() {
override public func layoutSubviews() {
super.layoutSubviews()
self.gradeView.frame = self.bounds
self.blurView.frame = self.bounds

Some files were not shown because too many files have changed in this diff Show More