Skip to content

Commit

Permalink
Add properties from PandaMom
Browse files Browse the repository at this point in the history
  • Loading branch information
wordlessj committed Jul 21, 2017
1 parent 75d6f49 commit 96843b5
Show file tree
Hide file tree
Showing 173 changed files with 8,218 additions and 1,442 deletions.
612 changes: 598 additions & 14 deletions Panda.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

89 changes: 74 additions & 15 deletions Sources/Extensions/Font.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,110 @@
// Font.swift
// Panda
//
// Created by Javier on 11/2/16.
// Copyright © 2016 Javier. All rights reserved.
// Copyright (c) 2017 Javier Zhang (https://wordlessj.github.io/)
//
// 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 protocol FontContainer {
func font(_ value: UIFont?) -> Self
public protocol FontContainer: class {
var containedFont: UIFont? { get set }
}

extension FontContainer {
extension PandaChain where Object: FontContainer {
@discardableResult
public func font(_ value: UIFont?) -> PandaChain {
object.containedFont = value
return self
}

@discardableResult
public func font(style: UIFontTextStyle) -> Self {
public func font(style: UIFontTextStyle) -> PandaChain {
return font(.preferredFont(forTextStyle: style))
}

@available(iOS 10.0, *)
@discardableResult
public func font(size: CGFloat) -> Self {
public func font(style: UIFontTextStyle, compatibleWith traitCollection: UITraitCollection?) -> PandaChain {
return font(.preferredFont(forTextStyle: style, compatibleWith: traitCollection))
}

@discardableResult
public func font(size: CGFloat) -> PandaChain {
return font(.systemFont(ofSize: size))
}

@available(iOS 8.2, *)
@discardableResult
public func font(size: CGFloat, weight: UIFont.Weight) -> Self {
public func font(size: CGFloat, weight: UIFont.Weight) -> PandaChain {
return font(.systemFont(ofSize: size, weight: weight))
}

@discardableResult
public func font(boldSize size: CGFloat) -> Self {
public func font(boldSize size: CGFloat) -> PandaChain {
return font(.boldSystemFont(ofSize: size))
}

@discardableResult
public func font(italicSize size: CGFloat) -> Self {
public func font(italicSize size: CGFloat) -> PandaChain {
return font(.italicSystemFont(ofSize: size))
}

@available(iOS 9.0, *)
@discardableResult
public func font(monospacedDigitSize size: CGFloat, weight: UIFont.Weight) -> Self {
public func font(monospacedDigitSize size: CGFloat, weight: UIFont.Weight) -> PandaChain {
return font(.monospacedDigitSystemFont(ofSize: size, weight: weight))
}
}

extension UIButton: FontContainer {}
extension UILabel: FontContainer {}
extension UITextField: FontContainer {}
extension UITextView: FontContainer {}
extension UIButton: FontContainer {
public var containedFont: UIFont? {
get { return titleLabel?.font }
set { titleLabel?.font = newValue }
}
}

extension UILabel: FontContainer {
public var containedFont: UIFont? {
get { return font }
set { font = newValue }
}
}

extension UISimpleTextPrintFormatter: FontContainer {
public var containedFont: UIFont? {
get { return font }
set { font = newValue }
}
}

extension UITextField: FontContainer {
public var containedFont: UIFont? {
get { return font }
set { font = newValue }
}
}

extension UITextView: FontContainer {
public var containedFont: UIFont? {
get { return font }
set { font = newValue }
}
}
39 changes: 39 additions & 0 deletions Sources/Extensions/PandaChain.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// PandaChain.swift
// Panda
//
// Copyright (c) 2017 Javier Zhang (https://wordlessj.github.io/)
//
// 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

public struct PandaChain<Object> {
public var object: Object
}

public protocol PandaChainable {}

extension PandaChainable {
/// Panda extensions.
public var panda: PandaChain<Self> { return PandaChain(object: self) }
}

extension NSObject: PandaChainable {}
57 changes: 52 additions & 5 deletions Sources/Extensions/UIButtonExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,63 @@
// UIButtonExtensions.swift
// Panda
//
// Created by Javier on 11/2/16.
// Copyright © 2016 Javier. All rights reserved.
// Copyright (c) 2017 Javier Zhang (https://wordlessj.github.io/)
//
// 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 UIButton {
extension PandaChain where Object: UIButton {
@discardableResult
public func title(_ title: String?, for state: UIControlState = .normal) -> PandaChain {
object.setTitle(title, for: state)
return self
}

@discardableResult
public func attributedTitle(_ title: NSAttributedString?, for state: UIControlState = .normal) -> PandaChain {
object.setAttributedTitle(title, for: state)
return self
}

@discardableResult
public func titleColor(_ color: UIColor?, for state: UIControlState = .normal) -> PandaChain {
object.setTitleColor(color, for: state)
return self
}

@discardableResult
public func titleShadowColor(_ color: UIColor?, for state: UIControlState = .normal) -> PandaChain {
object.setTitleShadowColor(color, for: state)
return self
}

@discardableResult
public func backgroundImage(_ image: UIImage?, for state: UIControlState = .normal) -> PandaChain {
object.setBackgroundImage(image, for: state)
return self
}

@discardableResult
public func font(_ value: UIFont?) -> Self {
titleLabel?.font = value
public func image(_ image: UIImage?, for state: UIControlState = .normal) -> PandaChain {
object.setImage(image, for: state)
return self
}
}
37 changes: 35 additions & 2 deletions Sources/Extensions/UIViewExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,45 @@
// UIViewExtensions.swift
// Panda
//
// Created by Javier on 10/31/16.
// Copyright © 2016 Javier. All rights reserved.
// Copyright (c) 2017 Javier Zhang (https://wordlessj.github.io/)
//
// 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 PandaChain where Object: UIView {
@discardableResult
public func contentCompressionResistancePriority(_ priority: UILayoutPriority,
for axis: UILayoutConstraintAxis) -> PandaChain {
object.setContentCompressionResistancePriority(priority, for: axis)
return self
}

@discardableResult
public func contentHuggingPriority(_ priority: UILayoutPriority,
for axis: UILayoutConstraintAxis) -> PandaChain {
object.setContentHuggingPriority(priority, for: axis)
return self
}
}

extension UIView {
@discardableResult
public func addSubviews(_ views: UIView...) -> Self {
Expand Down
28 changes: 28 additions & 0 deletions Sources/Properties/QuartzCore/CAAnimation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// CAAnimation.swift
// Panda
//
// Baby of PandaMom. DO NOT TOUCH.
//

import QuartzCore

extension PandaChain where Object: CAAnimation {
@discardableResult
public func timingFunction(_ value: CAMediaTimingFunction?) -> PandaChain {
object.timingFunction = value
return self
}

@discardableResult
public func delegate(_ value: CAAnimationDelegate?) -> PandaChain {
object.delegate = value
return self
}

@discardableResult
public func isRemovedOnCompletion(_ value: Bool) -> PandaChain {
object.isRemovedOnCompletion = value
return self
}
}
16 changes: 16 additions & 0 deletions Sources/Properties/QuartzCore/CAAnimationGroup.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// CAAnimationGroup.swift
// Panda
//
// Baby of PandaMom. DO NOT TOUCH.
//

import QuartzCore

extension PandaChain where Object: CAAnimationGroup {
@discardableResult
public func animations(_ value: [CAAnimation]?) -> PandaChain {
object.animations = value
return self
}
}
28 changes: 28 additions & 0 deletions Sources/Properties/QuartzCore/CABasicAnimation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// CABasicAnimation.swift
// Panda
//
// Baby of PandaMom. DO NOT TOUCH.
//

import QuartzCore

extension PandaChain where Object: CABasicAnimation {
@discardableResult
public func fromValue(_ value: Any?) -> PandaChain {
object.fromValue = value
return self
}

@discardableResult
public func toValue(_ value: Any?) -> PandaChain {
object.toValue = value
return self
}

@discardableResult
public func byValue(_ value: Any?) -> PandaChain {
object.byValue = value
return self
}
}
16 changes: 16 additions & 0 deletions Sources/Properties/QuartzCore/CADisplayLink.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// CADisplayLink.swift
// Panda
//
// Baby of PandaMom. DO NOT TOUCH.
//

import QuartzCore

extension PandaChain where Object: CADisplayLink {
@discardableResult
public func isPaused(_ value: Bool) -> PandaChain {
object.isPaused = value
return self
}
}
Loading

0 comments on commit 96843b5

Please sign in to comment.