SwiftyBase
SwiftyBase 使得处理用 Swift 创建的新项目变得简单。
为什么使用 SwiftyBase?
- 在软件开发中,我们都知道我们需要根据需求重用代码,因此我们必须利用我们的代码并付出更少的努力。我首先会向您展示一个示例:首先创建一个基于 baseViewController 的 viewcontroller,然后创建一个基于 base view 的 view,在控制器中初始化该视图,我们可以在另一个控制器中使用这个视图...这就是 baseview 的主要用途。在 storyboard 或一个 viewcontroller 中,其具有自己的视图。我们都知道,如果我们有自己的视图,则它将不能用于另一个控制器,因此我们可以在 baseview 上实现它,并通过简单的初始化多次使用它。
基础项目包含
- BaseViewController.swift
- BaseView.swift
- BaseNavigationController.swift
- 侧边菜单
扩展
- 数据
- 日期
- 字典
- NSArray
- NSDictionary
- UIColor
- UINavigationController
- UIScrollView
- UITableView
- UITextField
- UIViewController
- UIFont
- UIView
- String
- UIImage
实用工具
- AppBaseLayout
- AppConstants
- AppUtility
- AppInterFaceUtility
- AppLocationManager
- AppTimer
- AppAlert
- AppPreferencesExplorer
- AppPlistManger
- AppImageUploadManager
- AppEventBus
控件
- BaseImageView - 通过设置图像 URL 来设置图像,并提供捕获支持和清除捕获
- 基础按钮 - 单一类访问的多按钮
- 全屏图像查看器(ImageViewer)
- BaseRoundMenu
- 基础ProgressHUD - 类似于MBProgressView
- 基础标签 - 单一类访问的多标签
- 基础文本字段 - 单一类访问的多文本字段
- BaseScrollView
- BaseSegment
- BasePopOverMenu
- BaseNotificationBadge
需求
- iOS 9.0+
- Xcode 8
集成
CocoaPods (iOS 9)
您可以使用CocoaPods将SwiftyBase
添加到您的Podfile
中安装
platform :ios, '9.0'
use_frameworks!
target 'MyApp' do
pod 'SwiftyBase'
end
请注意,这需要CocoaPods版本为36,并且您的iOS部署目标至少为9.0
Carthage (iOS 9+)
您可以使用Carthage通过将其添加到您的Cartfile
中安装SwiftyBase
github "mspvirajpatel/SwiftyBase"
手动(iOS 9+)
要手动将此库用在他的项目中,您可以
- 只需将‘SwiftyBase/’拖到项目树中
使用说明
初始化
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")
}
基础圆角菜单
//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...")
}
}
应用PLIST管理器
//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
//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)
AppLocationManager
//using AppLocationManager
AppLocationManager.shared.locate { result in
switch result {
case .success(let locator):
...
break
case .failure( _):
...
break
}
}
In Progress
- 一段时间后添加描述。(进行中)
作者
Viraj Patel, [email protected]
许可证
SwiftyBase 遵循 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。