Latest 0.1.6.0
Homepage https://github.com/morganberger/BadasSwift
License MIT
Platforms ios 9.3
Frameworks UIKit, MapKit
Authors

CI Status
Version
License
Platform

Description

A colourful library of Swift extensions & custom stuffs!

Documentation:

  1. Extensions
  2. Models
  3. Views

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Note that the example project is currently a work in progress. I only use to test the stuff I code so it might be a little messy for now.

Requirements

  • iOS 9.3+
  • Xcode 9.4+
  • Swift 4.0+

Installation

BadasSwift is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'BadasSwift'

Documentation

Extensions

  • Bundle:

    Provides rapid access to app version & build numbers.

    public var versionNumber: String? { get }
    public var buildVersionNumber: String? { get }

    Usage:

    print("Version number: (Bundle.main.versionNumber)")

    Output -> "Version number: 1.0"

  • CharacterSet:

    static let urlAllowed: CharacterSet

    The urlAllowed variable is a CharacterSet union between:

    • .urlFragmentAllowed
    • .urlHostAllowed
    • .urlPasswordAllowed
    • .urlQueryAllowed
    • .urlUserAllowed

    It allows quick conversion from any string to a formatted acceptable url string.

    Usage:

    var urlStr = "http://google.com/search?q=Hello there, have a good day."
    urlStr = urlStr.addingPercentEncoding(withAllowedCharacters: .urlAllowed)!
    print(urlStr)

    Output -> "http://google.com/search?q=Hello%20there,%20have%20a%20good%20day."

  • CLLocationManager:

    public static var isAuthorized: Bool { get }

    Returns true if user authorized location always or whenInUse

  • Date:

    Returns a date string with asked format.

    public func formatedString(_ format: String) -> String

    Usage:

    print("Today's date is: (Date().formatedString("EEEE, MMM d, yyyy"))")

    Output -> "Today’s date is Monday, Oct 11, 2018"

  • NSLayoutConstraint:

    Provides some sweet real-time animation methods for NSLayoutConstraint.

    public func animateConstraintTo(_ value: CGFloat, for view: UIView, duration: Double)
    public func animateConstraintTo(_ value: CGFloat, for view: UIView, duration: Double, completion: @escaping () -> Void)
    
    public func setMultiplier(multiplier: CGFloat) -> NSLayoutConstraint
  • String:

    Got a string full of HTML tags? Change it to a attributed string with the methods below.

    public var html2AttributedString: NSAttributedString? { get }
    public var html2String: String { get }

    Usage:

    let htmlStr = "<h1>Very Big Title</h1>"
    let attributedStr = htmlStr.html2AttributedString()

    Or you could smoothly hash any string to MD5 if you feel like it!

    public func MD5Hex() -> String
    public func MD5base64() -> String
  • UIButton:

    func alignTextHorizontal(spacing: CGFloat = default)
  • UIImage:

    Convert image to black & white (grayscale).

    public func convertToGrayScale() -> UIImage

    Check is two images are identicals.

    public func isEqualTo(_ image: UIImage) -> Bool

    Scale any image to the provided CGSize.

    func scaleImage(scaleToSize: CGSize) -> UIImage
  • UIImageView:

    Fetches any web image from its url and applies it to the image view. Fast & async!

    public func setImageWithUrlString(_ urlStr: String, completion: @escaping (_ img: UIImage?) -> Void)

    Usage:

    anyImageView.setImageWithUrlString("http://something.com/someImage.png") { (img) in
      //the completion block send back the UIImage object that has been fetched.
    }
  • UIView:

    Get the root view in view hierarchy.

    public var rootView: UIView { get }

    Animate any view alpha to 1.0f. Can be called with or without completion block.

    public func showWithDuration(_ duration: Double)
    public func showWithDuration(_ duration: Double, completion: @escaping () -> Void)

    Animate any view alpha to 0.0f. Can be called with or without completion block.

    public func hideWithDuration(_ duration: Double)
    public func hideWithDuration(_ duration: Double, completion: @escaping () -> Void)

    Put 1px width border to any view with the wanted color. Mostly use for debugging purposes.

    public func putBorders(color: UIColor)

    Adds a vertical gradient layer with wanted colors to any view.

    public func putGradient(_ colors: CGColor...)

    Basically turn a view to an UIImage.

    public func takeSnapshot() -> UIImage?
  • UIViewController:

    public func setStatusBarColor(_ color: UIColor)

    Easily change the status bar color from any view controller!

    Usage:

    override func viewDidLoad() {
      super.viewDidLoad()
      self.setStatusBarColor(UIColor.blue)
    }
  • URL:

    public static func verifyUrl(string: String?) -> Bool

    Return true if url is correct/reachable. Else false.

Models

  • SnappingCollectionViewLayout:

    This class is a child of UICollectionViewFlowLayout.
    It provides simple snapping for collection view cells.

    Usage:

    let snapLayout:SnappingCollectionViewLayout = SnappingCollectionViewLayout()
    snapLayout.scrollDirection = .horizontal
    // Optional, you can ajust inset to better match your cells size.
    snapLayout.sectionInset = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 20)
    
    anyCollectionView.collectionViewLayout = snapLayout

    Result:

    BadasSwift

Views

  • VoteView:

    Very simple Objective-C coded view created to make some users rate some stuff. Could be anything.

    BadasSwift

    You can easily subclass this IBDesignable view and make it your own.
    It implements a few delegates:

    - (UIImage*)setSelectedImgName;
    - (UIImage*)setUnselectedImgName;
    - (int)setImageNumber;

    Those three are called during the draw(_ rect:CGRect) method. It depends of the developper’s preferences to set the UIImages and images number directly in the Storyboard or to call those delegates to set them. They’re like a lot of things in life: optional.

    - (void)voteDidChange:(int)voteResult;

    This one is called everytime a user taps an image within the view. Whenever the vote changes.

  • AwesomePageControl:

    A custom segmented control coded to be similar to the one used in the new version of the Chrome mobile app.

    Look how beautiful it is!

    BadasSwift

    You can use it as is but at this day it’s a work in progress so you’ll probably have a BAD TIME trying to add more segments to it.
    -> IBDesignable version coming very soon.

    Anyway, it has only one delegate method, which is:

    @objc optional func didTapControlAtIndex(_ index:Int) -> Void

    called everytime a new ‘segment’ is selected.

Author

morganberger, [email protected]

License

BadasSwift is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "BadasSwift",
    "version": "0.1.6.0",
    "summary": "A colourful library of Swift base classes extensions & customed stuff!",
    "swift_version": "4.2",
    "description": "A colourful library of Swift base classes extensions & customed stuff!n-> Currently a work in progress. Lot of cleaning to do here!",
    "homepage": "https://github.com/morganberger/BadasSwift",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "morganberger": "[email protected]"
    },
    "source": {
        "git": "https://github.com/morganberger/BadasSwift.git",
        "tag": "0.1.6.0"
    },
    "platforms": {
        "ios": "9.3"
    },
    "source_files": "BadasSwift/Classes/**/*.{h,m,swift}",
    "resources": [
        "BadasSwift/Classes/**/*.xib",
        "BadasSwift/Assets/assets.xcassets"
    ],
    "frameworks": [
        "UIKit",
        "MapKit"
    ],
    "subspecs": [
        {
            "name": "Resources",
            "resource_bundles": {
                "BadasSwift": [
                    "BadasSwift/Assets/**/*.{png}",
                    "BadasSwift/Classes/**/*.xib"
                ]
            }
        }
    ]
}

Pin It on Pinterest

Share This