SwiftyBase makes it easy to deal with new Project create in Swift.
- Why use the SwiftyBase
- Requirements
- Integration
- Usage
- Initialization
- BaseViewController
- BaseView
- BaseNavigationController
- BaseImageView
- BaseButton
- BaseProgressHUD
- BaseRoundMenu
- BaseLabel
- BaseTextField
- SideMenu
- AppImageUploadManager
- AppPlistManger
- AppPreferencesExplorer
- AppEventBus
- BaseScrollView
- BaseSegment
- BasePopOverMenu
- BaseNotificationBadge
- AppLocationManager
- In Progress
- Author
- 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:
- BaseViewController.swift
- BaseView.swift
- BaseNavigationController.swift
- SideMenu
Extensions :
- Data
- Date
- Dictionary
- NSArray
- NSDictionary
- UIColor
- UINavigationController
- UIScrollView
- UITableView
- UITextField
- UIViewController
- UIFont
- UIView
- String
- UIImage
Utilities:
- AppBaseLayout
- AppConstants
- AppUtility
- AppInterFaceUtility
- AppLocationManager
- AppTimer
- AppAlert
- AppPreferencesExplorer
- AppPlistManger
- AppImageUploadManager
- AppEventBus
Controls:
- BaseImageView - with set Url image with catch support & Clear Catch
- BaseButton - Multiple Button with single class access
- Full screen Image Viewer (ImageViewer)
- BaseRoundMenu
- BaseProgressHUD - Like MBProgressView
- BaseLabel - Multiple BaseLabel with single class access
- BaseTextField - Multiple Textfield with single class access
- BaseScrollView
- BaseSegment
- BasePopOverMenu
- BaseNotificationBadge
- iOS 9.0+
- Xcode 8
You can use CocoaPods to install SwiftyBase
by adding it to your Podfile
:
platform :ios, '9.0'
use_frameworks!
target 'MyApp' do
pod 'SwiftyBase'
end
Note that this requires CocoaPods version 36, and your iOS deployment target to be at least 9.0:
You can use Carthage to install SwiftyBase
by adding it to your Cartfile
:
github "mspvirajpatel/SwiftyBase"
To use this library in your project manually you may:
- Just drag ‘SwiftyBase/’ to the project tree
import SwiftyBase
//If Create ViewContoller using BaseViewController
class ListController: BaseViewController {
// MARK: - Attributes -
// MARK: - Lifecycle -
init() {
}
}
//If Create ListView using BaseView
class ListView: BaseView{
// MARK: - Attributes -
// MARK: - Lifecycle -
override init(frame: CGRect) {
super.init(frame:frame)
}
}
//using BaseNavigationController
let listview : ListController = ListController()
let baseNavigation : BaseNavigationController = BaseNavigationController(rootViewController: listview)
//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()
//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())
//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")
}
//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)")
}
//using BaseLabel for set diffrent types of Buttons
let lblUserName : BaseLabel = BaseLabel(labelType: .small, superView: self)
let lblUserRealName = BaseLabel(labelType: .large, superView: self)
//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)
//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)
//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...")
}
}
//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] = []
...
}
//using AppPreferencesExplorer open Settings Page in IPhone or IPad
do{
try AppPreferencesExplorer.open(.locationServices)
}
catch let error{
print(error.localizedDescription)
}
//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")
//using BaseScrollView ( ScrollTypes : both , horizontal, vertical )
let scrollView = BaseScrollView.init(scrollType: .both, superView: self)
//using BaseSegment
let baseSegment = BaseSegment.init(titleArray: ["Sign In", "Sign Up", "Forgot"], iSuperView: containerView)
baseSegment.setSegmentTabbedEvent { (selectedIndex) in
print("SelectedIndex Segment:\(selectedIndex)")
}
//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
}) {
}
//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)
//using AppLocationManager
AppLocationManager.shared.locate { result in
switch result {
case .success(let locator):
...
break
case .failure( _):
...
break
}
}
- Description after some time added.(In Progress)
Viraj Patel, [email protected]
SwiftyBase is available under the MIT license. See the LICENSE file for more info.