SwiftyBase 1.2.22

SwiftyBase 1.2.22

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Sep 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Viraj Patel.



SwiftyBase 1.2.22

  • By
  • Viraj Patel

SwiftyBase

BuddyBuild

SwiftyBase makes it easy to deal with new Project create in Swift.

  1. Why use the SwiftyBase
  2. Requirements
  3. Integration
  4. Usage
  5. In Progress
  6. Author

Why use the SwiftyBase?

  • In software development we all know that we have to reuse code as per as requirement so we have to utilise our code with less effort I will show you one demo on that first make one viewcontroller of baseviewcontroller then make one view of base view initialize this view in controller we can use this view in another controller too …that’s the main purpose of baseview In storyboard or in one view controller have its own view..We all know that if we have work in owns view, then it will not use for another controller so we can implement on baseview & use it another times with simple initialize.

In Base Project included:

  1. BaseViewController.swift
  2. BaseView.swift
  3. BaseNavigationController.swift
  4. SideMenu

Extensions :

  1. Data
  2. Date
  3. Dictionary
  4. NSArray
  5. NSDictionary
  6. UIColor
  7. UINavigationController
  8. UIScrollView
  9. UITableView
  10. UITextField
  11. UIViewController
  12. UIFont
  13. UIView
  14. String
  15. UIImage

Utilities:

  1. AppBaseLayout
  2. AppConstants
  3. AppUtility
  4. AppInterFaceUtility
  5. AppLocationManager
  6. AppTimer
  7. AppAlert
  8. AppPreferencesExplorer
  9. AppPlistManger
  10. AppImageUploadManager
  11. AppEventBus

Controls:

  1. BaseImageView - with set Url image with catch support & Clear Catch
  2. BaseButton - Multiple Button with single class access
  3. Full screen Image Viewer (ImageViewer)
  4. BaseRoundMenu
  5. BaseProgressHUD - Like MBProgressView
  6. BaseLabel - Multiple BaseLabel with single class access
  7. BaseTextField - Multiple Textfield with single class access
  8. BaseScrollView
  9. BaseSegment
  10. BasePopOverMenu
  11. BaseNotificationBadge

Requirements

  • iOS 9.0+
  • Xcode 8

Integration

Manually (iOS 9+)

To use this library in your project manually you may:

  1. Just drag ‘SwiftyBase/’ to the project tree

Usage

Initialization

import SwiftyBase

BaseViewController

//If Create ViewContoller using BaseViewController

class ListController: BaseViewController {

    // MARK: - Attributes -
    
    // MARK: - Lifecycle -
    
    init() {

    }
    
}

BaseView

//If Create ListView using BaseView

class ListView: BaseView{
    
    // MARK: - Attributes -
    
    // MARK: - Lifecycle -
    
    override init(frame: CGRect) {
        super.init(frame:frame) 
        
    }
}

BaseNavigationController

//using BaseNavigationController
let listview : ListController = ListController()
        
let baseNavigation : BaseNavigationController = BaseNavigationController(rootViewController: listview)

BaseImageView

//using BaseImageView for set Image Local or Remote URL

let imgView : BaseImageView = BaseImageView(type: .profile, superView: self)
imgView.layer.setValue("imgView", forKey: ControlConstant.name)

//Set Remote URL for Download and set in Image View
imgView.setImageURL("Enter Your URL")
        
//For Full Screen Image Show on tap on Image
imgView.setupForImageViewer()

BaseButton

//using BaseButton for set Button with case primary, secondary, radio, rounded Close, close, checkbox, dropdown, transparent 
 
let btnPrimary : BaseButton = BaseButton.init(ibuttonType: .primary, iSuperView: self)
btnPrimary.layer.setValue("btnPrimary", forKey: ControlConstant.name)
btnPrimary.setTitle("Primary Button", for: UIControlState())
        
let btnSecondary : BaseButton = BaseButton.init(ibuttonType: .secondary, iSuperView: self)
btnSecondary.layer.setValue("btnSecondary", forKey: ControlConstant.name)
btnSecondary.setTitle("Secondary Button", for: UIControlState())

BaseProgressHUD

//Just the loader

BaseProgressHUD.shared.showInView(view: view)
// Add title and footer text
BaseProgressHUD.shared.showInView(view: view, withHeader: "Loading", andFooter: "Please wait...")
// Set color to the header, footer, loader or to the background view

BaseProgressHUD.setHeaderColor(color: UIColor.blue)
BaseProgressHUD.setFooterColor(color: UIColor.blue)
BaseProgressHUD.setLoaderColor(color: UIColor.blue)
BaseProgressHUD.setBackgroundColor(color: UIColor.white)
// Customize: Set color the the background view and let header, footer and loader infer a contrast color
BaseProgressHUD.setBackgroundColor(color: UIColor.white, automaticTextColor: true)
// Or show in a window
BaseProgressHUD.shared.showInWindow(window: window, withHeader: "Loading", andFooter: "Please wait...")
// Hide the HUD
BaseProgressHUD.shared.hide()
// Check if HUD is already being displayed
if BaseProgressHUD.shared.isActive {
    print("Currently showing HUD")
} else {
    print("HUD is currently hidden")
}

BaseRoundMenu

//using BaseRoundMenu for set Button with case center,topLeft,topRight,bottomLeft,bottomRight

let btncenter = BaseRoundMenu(withPosition: .center, size: 50.0, numberOfPetals: 10, images:[])
let btntopLeft = BaseRoundMenu(withPosition: .topLeft, size: 50.0, numberOfPetals: 4, images:[])
let btntopRight = BaseRoundMenu(withPosition: .topRight, size: 50.0, numberOfPetals: 4, images:[])
let btnbottomLeft = BaseRoundMenu(withPosition: .bottomLeft, size: 50.0, numberOfPetals: 4, images:[])
let btnbottomRight = BaseRoundMenu(withPosition: .bottomRight, size: 50.0, numberOfPetals: 4, images:[])

self.view.addSubview(btncenter)
self.view.addSubview(btntopLeft)
self.view.addSubview(btntopRight)
self.view.addSubview(btnbottomLeft)
self.view.addSubview(btnbottomRight)

btncenter = { (indexSelected) in
    debugPrint("Selected Index: \(indexSelected)")
}

BaseLabel

//using BaseLabel for set diffrent types of Buttons

let lblUserName : BaseLabel = BaseLabel(labelType: .small, superView: self)

let lblUserRealName = BaseLabel(labelType: .large, superView: self)

BaseTextField

//using BaseTextField for set diffrent types of BaseTextField like Password, Email

let baseTextField : BaseTextField = BaseTextField.init(iSuperView: self, TextFieldType: .primary)

let baseTextField : BaseTextField = BaseTextField.init(iSuperView: self, TextFieldType: .showPassword)

let baseTextField : BaseTextField = BaseTextField.init(iSuperView: self, TextFieldType: .withoutClear)

let baseTextField : BaseTextField = BaseTextField.init(iSuperView: self, TextFieldType: .noAutoScroll)

SideMenu

//using SideMenu for set Application Menu SideMenu
//SideMenu is a simple and versatile side menu control

let menuLeftNavigationController = UISideMenuNavigationController(rootViewController: YourViewController)
menuLeftNavigationController.leftSide = true
// UISideMenuNavigationController is a subclass of UINavigationController, so do any additional configuration 
// of it here like setting its viewControllers. If you're using storyboards, you'll want to do something like:
// let menuLeftNavigationController = storyboard!.instantiateViewController(withIdentifier: "LeftMenuNavigationController") as! UISideMenuNavigationController
SideMenuManager.menuLeftNavigationController = menuLeftNavigationController

let menuRightNavigationController = UISideMenuNavigationController(rootViewController: YourViewController)
// UISideMenuNavigationController is a subclass of UINavigationController, so do any additional configuration
// of it here like setting its viewControllers. If you're using storyboards, you'll want to do something like:
// let menuRightNavigationController = storyboard!.instantiateViewController(withIdentifier: "RightMenuNavigationController") as! UISideMenuNavigationController
SideMenuManager.menuRightNavigationController = menuRightNavigationController

// Enable gestures. The left and/or right menus must be set up above for these to work.
// Note that these continue to work on the Navigation Controller independent of the view controller it displays!
SideMenuManager.menuAddPanGestureToPresent(toView: self.navigationController!.navigationBar)
SideMenuManager.menuAddScreenEdgePanGesturesToPresent(toView: self.navigationController!.view)


// For Custom Open with Button Click
present(SideMenuManager.menuLeftNavigationController!, animated: true, completion: nil)

// Similarly, to dismiss a menu programmatically, you would do this:
dismiss(animated: true, completion: nil)

AppImageUploadManager

//using AppImageUploadManager for Multiple Image Upload and track with number of remain with Progress

//Add Upload in Multiple Images 

var arrImage : [UIImage]? = [Add Your Images]

let isUploadAdded : Bool = AppImageUploadManager.sharedInstance.addImageForUpload(arrImage: arrImage!)
if isUploadAdded
{
    print("new Image Added")
}


//Progress Getting

AppImageUploadManager.sharedInstance.setUpdateProgressStatusEven { (wasSuccessfull, object) in
    // object is Kind of "object as! NSArray"

    self.updateImageProgress(arrCount: object as! NSArray)
}

open func updateImageProgress(arrCount : NSArray) -> Void
{
    print("Uploading (\(arrCount[0])\\\(arrCount[1]))")

    let uploadedImg : Float = Float(arrCount[0] as! Int)
    let totalImg : Float = Float(arrCount[1] as! Int)

    print("Completed : \(arrCount.firstObject)" , "Total : \(arrCount[1])")
    print("Progress : \(uploadedImg / totalImg)")

    if arrCount[0] as! Int == arrCount[1] as! Int
    {
        print("Upload is completed...")
    }
}

AppPlistManger

//using AppPlistManger for Management of Plist file store & read Data

//For Read Plist File (Link :- "Menu")
for menuData in AppPlistManager().readFromPlist("Your Plist File Name without .plist Extension") as! NSMutableArray
{
    let dicMenu : NSMutableDictionary = menuData as! NSMutableDictionary
    var arrItem : [NSDictionary] = []
    ...
}

AppPreferencesExplorer

//using AppPreferencesExplorer open Settings Page in IPhone or IPad

do{
    try AppPreferencesExplorer.open(.locationServices)
}
catch let error{
    print(error.localizedDescription)
}

AppEventBus

//AppEventBus using Notification Handling with hole Application 

//implement event handling methods

AppEventBus.onMainThread(target, name: "someEventName") { result in
    // UI thread
}

// or

AppEventBus.onBackgroundThread(target, name:"someEventName") { result in
    // API Access
}

//Post events

AppEventBus.post("someEventName")

//Post events with Parameters

AppEventBus.post("someEventName", sender: "VIRAJ")

// Expecting parameters

AppEventBus.onMainThread(target, name:"personFetchEvent") { result in
    let person : Stirng = result.object as Stirng
    println(person) // will output "VIRAJ"
}

//Remove all the observers from the target

AppEventBus.unregister(target)

//Remove observers of the same name from the target

AppEventBus.unregister(target, "someEventName")

BaseScrollView

//using BaseScrollView ( ScrollTypes : both , horizontal, vertical )

let scrollView = BaseScrollView.init(scrollType: .both, superView: self)

BaseSegment

//using BaseSegment 

let baseSegment = BaseSegment.init(titleArray: ["Sign In", "Sign Up", "Forgot"], iSuperView: containerView)
baseSegment.setSegmentTabbedEvent { (selectedIndex) in
    print("SelectedIndex Segment:\(selectedIndex)")
}

BasePopOverMenu

//using BasePopOverMenu set Globle Variable For Custom

let configuration = AppConfiguration.shared
configuration.menuRowHeight = ...
configuration.menuWidth = ...
configuration.textColor = ...
configuration.textFont = ...
configuration.tintColor = ...
configuration.borderColor = ...
configuration.borderWidth = ...
configuration.textAlignment = ...
configuration.ignoreImageOriginalColor = ...;
//// set 'ignoreImageOriginalColor' to YES, images color will be same as textColor

//From SenderView, Menu Without Images.
//
BasePopOverMenu.showForSender(sender: sender,with: ["Share"],
    done: { (selectedIndex) -> () in
        print(selectedIndex)
    }) {
}

//From SenderView, Menu With Images.
//
BasePopOverMenu.showForSender(sender: sender,with: ["Share"],menuImageArray: ["iconImageName"],
    done: { (selectedIndex) -> () in

        print(selectedIndex)
    }) {
   
}

//From SenderFrame/NavigationItem, Menu Without Images.
//
BasePopOverMenu.showFromSenderFrame(senderFrame: sender.frame,with: ["Share"],
    done: { (selectedIndex) -> () in

    }) {

}

//From SenderFrame/NavigationItem, Menu With Images.
//
BasePopOverMenu.showFromSenderFrame(senderFrame: sender.frame,with: ["Share"],menuImageArray: ["iconImageName"],
    done: { (selectedIndex) -> () in

    }) {
    
}

BaseNotificationBadge

//using BasePopOverMenu 

//To add a badge with default settings use this (This also applies to updating an existing badge):

view.badge(text: "5")

barButtonItem.badge(text: "7")


//To remove the badge:

view.badge(text: nil)

barButtonItem.badge(text: nil)


//Advanced Usage

let badgeAppearnce = AppBadgeAppearnce()
appearnce.backgroundColor = UIColor.blue //default is red
appearnce.textColor = UIColor.white // default is white
appearnce.alignment = .center //default is center
appearnce.textSize = 15 //default is 12
appearnce.distenceFromCenterX = 15 //default is 0
appearnce.distenceFromCenterY = -10 //default is 0
appearnce.allowShadow = true
appearnce.borderColor = .blue
appearnce.borderWidth = 1
view.badge(text: "Your text", appearnce: badgeAppearnce)

In Progress

  • Description after some time added.(In Progress)

Author

Viraj Patel, [email protected]

License

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