📦 常见的扩展和补充,以简化开发
LFBR-SwiftLib -
特性 🧞♂️
- 轻松关闭键盘
⌨️ - 了解你的互联网连接状态
📡 - 加密您的消息 🧙🏽♂️
- 在不进入 alertviewcontroller 的情况下启动警报
- 像时间戳一样管理时间
⏰ - 获取当前设备的尺寸和类型
📱 - 一些常用的正则表达式及其字符串扩展
- 创建带有 RGB 格式的 UIColors 的方法
🎨 - 无额外依赖
👻 - 单次集成,提供公共方法
- 公共扩展
- UIView, UITableView 和 UITableViewCell 扩展,以便更容易地以编程方式创建界面
- 泛型组件,以最简单的方式创建 UITableView 和 UITableViewCell
CocoaPods 安装
Podfile
pod 'LFBR.SwiftLib'
ReachabilityManager 类
检测您互联网连接的简单方法,让您向用户展示是否有互联网连接
//Initialize status of your internet connection
ReachabilityManager.sharedInstance.isInternetAvailable()
//Value to know if have internet connection
ReachabilityManager.sharedInstance.isInternetAvaliable
CommonCrypto 类
轻松加密您信息的方法
let sourceData = "AES256".data(using: .utf8)!
let password = "password"
let salt = AES256Crypter.randomSalt()
let iv = AES256Crypter.randomIv()
let key = try AES256Crypter.createKey(password: password.data(using: .utf8)!, salt: salt)
let aes = try AES256Crypter(key: key, iv: iv)
let encryptedData = try aes.encrypt(sourceData)
let decryptedData = try aes.decrypt(encryptedData)
print("Encrypted hex string: \(encryptedData.base64EncodedString())")
print("Decrypted hex string: \(decryptedData.base64EncodedString())")
MessageObject 类
让您轻松地在所有视图上方创建一个简单的警报视图控制器(让您在另一个线程中工作)
//Easy implementation
MessageObject.sharedInstance.showMessage.....
// Show alert view controller with custom message, title and ok title button
///
/// - Parameters:
/// - message: Message string
/// - title: Title string
/// - okMessage: Accept string
public func showMessage(_ message:String, title:String, okMessage:String)
/// Show alert view controller with custom message, title and OK custom button
///
/// - Parameters:
/// - message: Message string
/// - title: Title string
/// - okAction: OK action behavoir
public func showMessage(_ message:String, title:String, okAction:UIAlertAction)
/// Show alert view controller with custom message, title, OK custom button and Cancel custom button
///
/// - Parameters:
/// - message: Message string
/// - title: Title string
/// - okAction: OK action behavoir
/// - cancelAction: Cancel action behavoir
public func showMessage(_ message:String, title:String, okAction:UIAlertAction, cancelAction:UIAlertAction)
/// Show alert view controller with custom message, title, OK custom button and Cancel title button
///
/// - Parameters:
/// - message: Message string
/// - title: Title string
/// - okAction: OK action behavoir
/// - cancelMessage: Cancel string
public func showMessage(_ message:String, title:String, okAction:UIAlertAction, cancelMessage:String)
/// Show alert view controller with a textview instead of this
///
/// - Parameters:
/// - message: Message string
/// - title: Title string
/// - okMessage: Accept string
/// - cancelMessage: Cancel string
/// - textPlaceHolder: Default string for your textview
/// - completion: Function to excecute after any button was clicked
public func showMessageWithTextView(_ message:String, title:String, okMessage:String, cancelMessage:String, textPlaceHolder:String, completion:@escaping(String) ->Void)
为 iPhone 尺寸的类
//Return kind of iPhone size (IPHONE_4, IPHONE_5, IPHONE_6, IPHONE_6_PLUS, IPHONE_X, IPHONE_UNKNOWN)
var IPHONE_DEVICE: iPhoneDevices
AlertPickerSelectorViewController 类
类似于模态视图控制器的选择器实现
public protocol AlertPickerDelegate{
func dateSelected(_ dateSelected: Date, andTag: Int)
}
UIWindow 的扩展
/// Get top visible view controller
///
/// - Returns: Top view controller
func visibleViewController() -> UIViewController?
UIViewController
的扩展
对 /
/// Remove keyboard when tap over any part of windows
func hideKeyboardWhenTappedAround()
/// Remove keyboard when tap over any part of selected view
func hideKeyboardWhenTappedIn(currentView: UIView)
/// Dismiss keyboard
@objc func dismissKeyboard()
/// Get keyboard height
///
/// - Returns: Keyboard height
func heightKeyboard() -> CGFloat
Int
的扩展
对 /// Transform current int value to time representation by offset
///
/// - Returns: Date representation
func getDateByOffset() -> Date
Double
和 Float
的扩展
对 /// Return string representation with custom decimals and decimal separator
///
/// - Parameters:
/// - fractionDigits: number of digits after dot
/// - customDecimalSeparator: custom decimal separator, by default is dot ('.')
/// - Returns: String representation
func formatWithFractionDigits(_ fractionDigits: Int, customDecimalSeparator: String? = ".")
UIColor
的扩展
对 /// UIColor by RGB formtar
///
/// - Parameter rgb: RGB color with hex representation
convenience init(rgb: Int)
/// UIColor by red, green and blue values in interval to 0 to 255 representation
///
/// - Parameters:
/// - red: representation beetween 0 to 255
/// - green: representation beetween 0 to 255
/// - blue: representation beetween 0 to 255
convenience init(red: Int, green: Int, blue: Int)
Date
的扩展
对 /// Returns the amount of years from another date
func years(from date: Date) -> Int
/// Returns the amount of months from another date
func months(from date: Date) -> Int
// Returns the amount of weeks from another date
func weeks(from date: Date) -> Int
/// Returns the amount of days from another date
func days(from date: Date) -> Int
/// Returns the amount of hours from another date
func hours(from date: Date) -> Int
/// Returns the amount of minutes from another date
func minutes(from date: Date) -> Int
/// Returns the amount of seconds from another date
func seconds(from date: Date) -> Int
/// Returns the amount of nanoseconds from another date
func nanoseconds(from date: Date) -> Int
/// Returns the a custom time interval description from another date
func offset(from date: Date) -> String
/// Return yyy MMM dd HH:mm from current date
///
/// - Returns: date as descriptive string
func getTimeWithYYYMMMDDHHmmFormat() -> String
/// Return dd MMM yyy HH:mm from current date
///
/// - Returns: date as descriptive string
func getTimeWithDDMMMYYYHHmmFormat() -> String
/// Add some days to current date
///
/// - Parameter days: days to add to your current date
/// - Returns: date as dd-MMM format with
func getLeftDaysFrom(days:Int) -> String
/// Return date as string
///
/// - Parameter format: formate descriptio
/// - Returns: date as descriptive string
func getTimeBy(format: String) -> String
/// Transform current date value to int representation by offset
///
/// - Returns: Int64 representation
func getTimeStamp() -> Int64
String
的扩展
对 /// String representation by urlQueryAllowed
///
/// - Returns: string representation validated to url encode
func encodeUrl() -> String?
/// Decode url to get friendly string
///
/// - Returns: string decoded
func decodeUrl() -> String?
/// Check if your current string can be used like URL
///
/// - Returns: Validate if current string is URL
func isURL () -> Bool
/// Check if your current string can be used like email
///
/// - Returns: Validate if your string is an email
func isEmail() -> Bool
/// Check if your current string can be used like number
///
/// - Returns: Validate if your string is a number
func isNumber() -> Bool
/// Transform your current string to Float with 2 decimals, if your string doesn't have valid format then your response will be 0
///
/// - Returns: Float representation
func toFloat(_ localeIdentifier: String? = nil) -> Float
/// Integer reprentation of your current string, if your string doesn't have valid format then your response will be 0
var int : Int
/// Transform your current string to NSAttributedString, changing numbers to NumberFormatter
///
/// - Returns: NSAttributedString with number formatter
func sliderAttributeString() -> NSAttributedString
NSString
的扩展
对 /// Transform your current string to NSAttributedString, changing fonts from your seleted array of strings
///
/// - Parameters:
/// - boldPartsOfString: Array to strings to need his font changed
/// - font: Font for all your string
/// - boldFont: Font for your strings selected
/// - Returns: NSAttributedString with string font changed
func getdBoldedText(boldPartsOfString: Array<NSString>, font: UIFont!, boldFont: UIFont!) -> NSAttributedString
特别感谢
Brian Voong来自Build That App,他是UIView+anchors.swift和GenericTableViewController.swift的创建者
许可信息
MIT 许可证
版权所有(c)2019 Luis Fernando Bustos Ramírez [email protected]
特此免费许可任何获得本软件及其相关文档副本(以下简称“软件”)的人,在此软件中不受限制地处理软件,包括但不限于使用、复制、修改、合并、发布、分发、转让和/或销售软件副本,并允许向软件提供方做上述操作,但需遵守以下条件
所有副本或软件的大量部分都必须包含上述版权声明和本许可声明。
软件按原样提供,没有任何明示或暗示的保证,包括但不限于适销性、特定用途适用性和非侵权性。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任承担责任,无论基于合同、侵权或其他原因,不论索赔、损害或其他责任是否因本软件或与使用或以其他方式处理本软件有关。