TxExtensionWrapper
public struct TxExtensionWrapper<Base>
扩展命名空间
-
泛型
Declaration
Swift
public let base: Base
-
构造函数
Declaration
Swift
public init(_ base: Base)
Parameters
base
泛型
-
角标view
Declaration
Swift
public var badgeView: BadgeControl { get }
-
添加带文本内容的Badge, 默认右上角, 红色, 18pts
Add Badge with text content, the default utxer right corner, red backgroundColor, 18pts
Declaration
Swift
public func addBadge(text: String)
Parameters
text
文本字符串
-
添加带数字的Badge, 默认右上角,红色,18pts
Add the Badge with numbers, the default utxer right corner, red backgroundColor, 18pts
Declaration
Swift
public func addBadge(number: Int)
Parameters
number
整形数字
-
添加带颜色的小圆点, 默认右上角, 红色, 8pts
Add small dots with color, the default utxer right corner, red backgroundColor, 8pts
Declaration
Swift
public func addDot(color: UIColor? = .red)
Parameters
color
颜色
-
设置Badge的偏移量, Badge中心点默认为其父视图的右上角
Set Badge offset, Badge center point defaults to the top right corner of its parent view
Declaration
Swift
public func moveBadge(x: CGFloat, y: CGFloat)
Parameters
x
X轴偏移量 (x<0: 左移, x>0: 右移) axis offset (x <0: left, x> 0: right)
y
Y轴偏移量 (y<0: 上移, y>0: 下移) axis offset (Y <0: up, y> 0: down)
-
设置Badge伸缩的方向
Setting the direction of Badge expansion
txBadgeViewFlexModeHead, 左伸缩 Head Flex : <==● txBadgeViewFlexModeTail, 右伸缩 Tail Flex : ●==> txBadgeViewFlexModeMiddle 左右伸缩 Middle Flex : <=●=>
Declaration
Swift
public func setBadge(flexMode: BadgeViewFlexMode = .tail)
Parameters
flexMode
Default is txBadgeViewFlexModeTail
-
设置Badge的高度,因为Badge宽度是动态可变的,通过改变Badge高度,其宽度也按比例变化,方便布局
(注意: 此方法需要将Badge添加到控件上后再调用!!!)
Set the height of Badge, because the Badge width is dynamically and variable.By changing the Badge height in proportion to facilitate the layout.
(Note: this method needs to add Badge to the controls and then use it !!!)
Declaration
Swift
public func setBadge(height: CGFloat)
Parameters
points
高度大小
-
显示Badge
Declaration
Swift
public func showBadge()
-
隐藏Badge
Declaration
Swift
public func hiddenBadge()
Digital increase /decrease, note: the following method atxlies only to cases where the Badge content is purely numeric
-
badge数字加1
Declaration
Swift
public func increase()
-
badge数字加number
Declaration
Swift
public func increaseBy(number: Int)
-
badge数字加1
Declaration
Swift
public func decrease()
-
badge数字减number
Declaration
Swift
public func decreaseBy(number: Int)
-
角标view
Declaration
Swift
public var badgeView: BadgeControl { get }
-
添加带文本内容的Badge, 默认右上角, 红色, 18pts
Add Badge with text content, the default utxer right corner, red backgroundColor, 18pts
Declaration
Swift
public func addBadge(text: String)
Parameters
text
文本字符串
-
添加带数字的Badge, 默认右上角,红色,18pts
Add the Badge with numbers, the default utxer right corner, red backgroundColor, 18pts
Declaration
Swift
public func addBadge(number: Int)
Parameters
number
整形数字
-
添加带颜色的小圆点, 默认右上角, 红色, 8pts
Add small dots with color, the default utxer right corner, red backgroundColor, 8pts
Declaration
Swift
public func addDot(color: UIColor? = .red)
Parameters
color
颜色
-
设置Badge的偏移量, Badge中心点默认为其父视图的右上角
Set Badge offset, Badge center point defaults to the top right corner of its parent view
Declaration
Swift
public func moveBadge(x: CGFloat, y: CGFloat)
Parameters
x
X轴偏移量 (x<0: 左移, x>0: 右移) axis offset (x <0: left, x> 0: right)
y
Y轴偏移量 (y<0: 上移, y>0: 下移) axis offset (Y <0: up, y> 0: down)
-
设置Badge伸缩的方向
Setting the direction of Badge expansion
txBadgeViewFlexModeHead, 左伸缩 Head Flex : <==● txBadgeViewFlexModeTail, 右伸缩 Tail Flex : ●==> txBadgeViewFlexModeMiddle 左右伸缩 Middle Flex : <=●=>
Declaration
Swift
public func setBadge(flexMode: BadgeViewFlexMode = .tail)
Parameters
flexMode
Default is txBadgeViewFlexModeTail
-
设置Badge的高度,因为Badge宽度是动态可变的,通过改变Badge高度,其宽度也按比例变化,方便布局
(注意: 此方法需要将Badge添加到控件上后再调用!!!)
Set the height of Badge, because the Badge width is dynamically and variable.By changing the Badge height in proportion to facilitate the layout.
(Note: this method needs to add Badge to the controls and then use it !!!)
Declaration
Swift
public func setBadge(height: CGFloat)
Parameters
height
高度大小
-
显示Badge
Declaration
Swift
public func showBadge()
-
隐藏Badge
Declaration
Swift
public func hiddenBadge()
Digital increase /decrease, note: the following method atxlies only to cases where the Badge content is purely numeric
-
badge数字加1
Declaration
Swift
public func increase()
-
badge数字加number
Declaration
Swift
public func increaseBy(number: Int)
-
badge数字加1
Declaration
Swift
public func decrease()
-
badge数字减number
Declaration
Swift
public func decreaseBy(number: Int)
-
角标view
Declaration
Swift
public var badgeView: BadgeControl { get }
-
添加带文本内容的Badge, 默认右上角, 红色, 18pts 传入nil时显示红色背景 Add Badge with text content, the default upper right corner, red backgroundColor, 18pts
Declaration
Swift
public func addBadge(text: String?)
Parameters
text
文本字符串
-
添加带数字的Badge, 默认右上角,红色,18pts 小于0时不显示 Add the Badge with numbers, the default upper right corner, red backgroundColor, 18pts
Declaration
Swift
public func addBadge(number: Int)
Parameters
number
整形数字
-
添加带颜色的小圆点, 默认右上角, 红色, 8pts
Add small dots with color, the default upper right corner, red backgroundColor, 8pts
Declaration
Swift
public func addDot(color: UIColor? = .red)
Parameters
color
颜色
-
设置Badge的偏移量, Badge中心点默认为其父视图的右上角
Set Badge offset, Badge center point defaults to the top right corner of its parent view
Declaration
Swift
public func moveBadge(x: CGFloat, y: CGFloat)
Parameters
x
X轴偏移量 (x<0: 左移, x>0: 右移) axis offset (x <0: left, x> 0: right)
y
Y轴偏移量 (y<0: 上移, y>0: 下移) axis offset (Y <0: up, y> 0: down)
-
设置Badge伸缩的方向
Setting the direction of Badge expansion
PPBadgeViewFlexModeHead, 左伸缩 Head Flex : <==● PPBadgeViewFlexModeTail, 右伸缩 Tail Flex : ●==> PPBadgeViewFlexModeMiddle 左右伸缩 Middle Flex : <=●=>
Declaration
Swift
public func setBadge(flexMode: BadgeViewFlexMode = .tail)
Parameters
flexMode
Default is PPBadgeViewFlexModeTail
-
设置Badge的高度,因为Badge宽度是动态可变的,通过改变Badge高度,其宽度也按比例变化,方便布局
(注意: 此方法需要将Badge添加到控件上后再调用!!!)
Set the height of Badge, because the Badge width is dynamically and variable.By changing the Badge height in proportion to facilitate the layout.
(Note: this method needs to add Badge to the controls and then use it !!!)
Declaration
Swift
public func setBadge(height: CGFloat)
Parameters
height
高度大小
-
显示Badge
Declaration
Swift
public func showBadge()
-
隐藏Badge
Declaration
Swift
public func hiddenBadge()
Digital increase /decrease, note: the following method applies only to cases where the Badge content is purely numeric
-
badge数字加1
Declaration
Swift
public func increase()
-
badge数字加number
Declaration
Swift
public func increaseBy(number: Int)
-
badge数字加1
Declaration
Swift
public func decrease()
-
badge数字减number
Declaration
Swift
public func decreaseBy(number: Int)
-
延时扩展
Declaration
Swift
public func delay(_ delay: Double, execute: @escaping () -> Void)
Parameters
delay
延时时间
execute
闭包执行
-
切换队列
当当前线程为主线程并且是主队列切换时,不再进行切换,而是直接执行代码块
Note
主线程可以执行非主队列的任务(如主线程中调用全局队列的同步函数) 避免当主线程执行非主队列任务时,主线程切换队列的开销 同时避免切换队列造成的执行时序问题Declaration
Swift
public func safeAsync(_ block: @escaping () -> Void)
Parameters
block
代码块
-
保证代码块只执行一次
Declaration
Swift
public static func once(token: String, block: () -> Void)
Parameters
token
唯一标识符
block
闭包
-
获取指定pod的指定Bundle,前提是pod以resource_bundle方式引入资源
Note
当使用framework方式引用三方库时,每一个三方库都会在Frameworks下面以一个单独的framework存在Declaration
Swift
public static func getBundle(bundleName: String, podName: String? = nil) -> Bundle?
Parameters
bundleName
bundleName
podName
podName,当使用framwork时使用,如果为nil,赋值为bundleName
-
16进制Data转字符串
Note
获取的推送token可以用这个进行转换Declaration
Swift
public var hexString: String { get }
-
Date格式化
Declaration
Swift
public func formatDate(format: DateFormateType) -> String
Parameters
format
格式化类型
Return Value
格式化后的字符串
-
Date格式化
Declaration
Swift
public func formatDate(formatStr: String) -> String
Parameters
format
日期格式
Return Value
格式化后的字符串
-
获取星期
Declaration
Swift
public var weekDay: String { get }
-
获取相对指定时间之前几天或者之后几天的日期,之前的填入负数
Declaration
Swift
public func getDateByDays(days: Int) -> Date
Parameters
days
日期,单位为天
-
秒级时间戳 - 10位
Declaration
Swift
public var timeStamp: Int { get }
-
获取秒级时间戳 - 10位
Declaration
Swift
public var timeStampStr: String { get }
-
获取毫秒级时间戳 - 13位
Declaration
Swift
public var milliTimeStamp: Int { get }
-
获取毫秒级时间戳 - 13位
Declaration
Swift
public var milliTimeStampStr: String { get }
-
获取当前时间
Declaration
Swift
public static func getCurrentTime() -> String
-
获取当前日期
Declaration
Swift
public static func getCurrentDate() -> String
-
时间戳(毫秒)转时间
Declaration
Swift
public var dateAsMilliStamp: Date { get }
-
时间戳转时间字符串
Declaration
Swift
public func toDateStrAsMilliStamp(format: DateFormateType) -> String
Parameters
format
时间格式化格式
-
时间戳(秒)转时间
Declaration
Swift
public var dateAsTimeStamp: Date { get }
-
时间戳(秒)转时间字符串
Declaration
Swift
public func toDateStrAsTimeStamp(format: DateFormateType) -> String
Parameters
format
时间格式化格式
-
根据对象获取类名
Declaration
Swift
public var className: String { get }
-
获取指定属性的值
Declaration
Swift
public func getValueOfProperty(property: String) -> AnyObject?
Parameters
property
属性
Return Value
属性值
-
设置指定属性的值
Declaration
Swift
public func setValueOfProperty(property: String, value: AnyObject)
Parameters
property
属性
value
属性新值
-
获取所有属性还有值
Declaration
Swift
public func getAllPropertysAndValue() -> [String : Any]
Return Value
属性以及对应的值
-
静态方法,获取对象的所有属性名称 获取对象的所有属性 注意:必须在获取类的class前添加@objcMembers,不然获取为空数组
Declaration
Swift
public static func getAllProperties(ignoredProperties: [String] = []) -> [String]
Return Value
属性列表
-
获取URL的参数
Declaration
Swift
public var parametersFromQueryString: [String : String]? { get }
-
去除浮点数后面多余的0
Declaration
Swift
public var removeSuffixZero: String { get }
-
数组去重,排序后数据保持顺序
Declaration
Swift
public func removeDuplicate<E>(_ repeated: (Base.Iterator.Element) -> E) -> [Base.Iterator.Element] where E : Equatable
Parameters
repeated
去重标准
-
keyPath的形式对数组排序
Declaration
Swift
public func sorted<T>(by keyPath: KeyPath<Base.Iterator.Element, T>) -> [Base.Iterator.Element] where T : Comparable
Parameters
keyPath
keyPath
Return Value
排序后的数组
-
将集合分组
Declaration
Swift
public func group<GroupingType>(by key: (Base.Iterator.Element) -> GroupingType) -> [[Base.Iterator.Element]] where GroupingType : Hashable
Parameters
key
分组依据
Return Value
分组后结果
-
截取字符串前指定位,异常情况返回原字符串
Declaration
Swift
public func getPrefix(count: Int) -> String
Parameters
count
位数值
Return Value
截取后的字符串
-
截取字符串后几位,异常情况返回原字符串
Declaration
Swift
public func getSuffix(count: Int) -> String
Parameters
count
位数值
Return Value
截取后的字符串
-
截取字符串,0位开始,左闭右开
Declaration
Swift
public func getSubString(start: Int, end: Int) -> String
Parameters
start
起始位
end
终止位
Return Value
截取后的字符串
-
时间转日期
Declaration
Swift
public func toDate(dateType: DateFormateType) -> Date?
Parameters
dateType
日期类型
Return Value
日期
-
时间转日期
Declaration
Swift
public func toDate(dateTypeStr: String) -> Date?
Parameters
dateType
日期类型格式
Return Value
日期
-
截取时间字符串中的某一部分
Declaration
Swift
public func getDateStr(dateType: DateFormateType) -> String
Parameters
dateType
日期类型
-
是否邮箱地址
Declaration
Swift
public var isEmail: Bool { get }
-
是否手机号
Declaration
Swift
public var isMobile: Bool { get }
-
是否身份证号
Declaration
Swift
public var isIDNumber: Bool { get }
-
是否车牌号
Declaration
Swift
public var isCarNumber: Bool { get }
-
是否http链接(包含https)
Declaration
Swift
public var isNetworkUrl: Bool { get }
-
中文转拼音 会有多音字问题,并且效率较低,不适合大批量数据
Declaration
Swift
public func toPinYin() -> String
Return Value
拼音
-
字符串转为类,限制主工程代码使用
Declaration
Swift
public var classOfMainBundle: AnyClass? { get }
-
url编码 对特殊符号编码
Declaration
Swift
public var urlEncode: String? { get }
-
url编码 对特殊符号不编码
Declaration
Swift
public var urlEncodeWithoutCharacters: String? { get }
-
url解码
Declaration
Swift
public var urlDecode: String? { get }
-
base64编码
Declaration
Swift
public var base64Encode: String? { get }
-
base64解码
Declaration
Swift
public var base64Decode: String? { get }
-
获取指定宽度、字体的字符串高度
不是绝对准确
Declaration
Swift
public func height(font: UIFont, width: CGFloat) -> CGFloat
Parameters
font
字体
width
宽度
-
获取指定高度、字体的字符串宽度
不是绝对准确
Declaration
Swift
public func width(font: UIFont, height: CGFloat) -> CGFloat
Parameters
font
字体
height
高度
-
转为富文本
Declaration
Swift
public var attributedString: NSMutableAttributedString { get }
-
添加字体
Declaration
Swift
public func addFontStyle(fontName: String = "", fontStyle: FontStyle, fontSize: CGFloat) -> NSMutableAttributedString
Parameters
fontName
字体名称
fontStyle
字体样式
fontSize
字体尺寸
-
添加下划线
Declaration
Swift
public func addUnderline(style underlineStyle: NSUnderlineStyle = .single, color underlineColor: UIColor? = nil) -> NSMutableAttributedString
Parameters
underlineStyle
下划线样式,默认为single
underlineColor
下划线颜色,默认为nil,nil时跟字体颜色保持相同
-
添加删除线
Declaration
Swift
public func addStrikethrough(style strikethroughStyle: NSUnderlineStyle = .single, color strikethroughColor: UIColor? = nil) -> NSMutableAttributedString
Parameters
strikethroughStyle
删除线样式,默认为single
strikethroughColor
删除线样式,默认为nil,nil时跟字体颜色保持相同
-
标识符
Note
重用时可使用Declaration
Swift
public var identifier: String { get }
-
颜色转hex值
Declaration
Swift
public var hexString: String? { get }
-
颜色的反色
Declaration
Swift
public var invertColor: UIColor { get }
-
红色值
Declaration
Swift
public var redColor: Int { get }
-
绿色值
Declaration
Swift
public var greenColor: Int { get }
-
蓝色值
Declaration
Swift
public var blueColor: Int { get }
-
颜色生成指定大小的UIImage
Declaration
Swift
public func toImage(size: CGSize) -> UIImage?
Parameters
size
图片尺寸
Return Value
图片
-
适配暗黑模式
Declaration
Swift
public func adaptDark(_ colorWithDark: UIColor? = nil) -> UIColor
Parameters
colorWithDark
暗黑模式下的颜色,默认为nil,取颜色反色
-
适配各种模式
Declaration
Swift
public func adapt(colorWithDark: UIColor? = nil) -> UIColor
Parameters
colorWithDark
暗黑模式颜色
-
粗体
Declaration
Swift
public static func boldFont(name fontName: String = "", size fontSize: CGFloat) -> UIFont
Parameters
fontName
字体名称,为空时使用系统字体,默认为空
fontSize
字体尺寸
-
斜体
Declaration
Swift
public static func italicFont(name fontName: String = "", size fontSize: CGFloat) -> UIFont
Parameters
fontName
字体名称,为空时使用系统字体,默认为空
fontSize
字体尺寸
-
粗体、斜体 如果粗体生成失败,则会返回斜体
Declaration
Swift
public static func boldItalicFont(name fontName: String = "", size fontSize: CGFloat) -> UIFont
Parameters
fontName
字体名称,为空时使用系统字体,默认为空
fontSize
字体尺寸
-
压缩图片 注意压缩后含有透明背景图片的背景会变成白色
Declaration
Swift
public func compress(type: ImageCompressType = .timeline) -> UIImage
Parameters
type
压缩类型
Return Value
压缩后的图片
-
设置图片尺寸
Declaration
Swift
public func setSize(reSize: CGSize) -> UIImage
Parameters
reSize
图片尺寸
Return Value
处理后的图片
-
缩放图片
Declaration
Swift
public func scaleImage(scaleSize: CGFloat) -> UIImage
Parameters
scaleSize
缩放比例
Return Value
缩放后的图片
-
图片旋转
Declaration
Swift
public func rotate(orientation: UIImage.Orientation) -> UIImage
Parameters
orientation
旋转方向
Return Value
旋转后的图片
-
修改UIImage的颜色
Declaration
Swift
public func withTintColor(color: UIColor) -> UIImage?
Parameters
color
修改成的颜色
Return Value
修改颜色后的UIImage
-
获取其他Bundle中的图片
Note
当使用framework方式引用三方库时,每一个三方库都会在Frameworks下面以一个单独的framework存在Declaration
Swift
@available(iOS 8.0, *) public static func getImage(named: String, bundleName: String, podName: String? = nil) -> UIImage?
Parameters
named
图片名称
bundleName
bundleName
podName
podName,当使用framwork时使用,如果为nil,赋值为bundleName
Return Value
UIImage?
-
关闭当前页面并跳转到新页面
Declaration
Swift
public func toViewControllerAndCloseSelf(_ viewController: UIViewController, animated: Bool = true)
Parameters
viewController
页面
animated
是否显示动画
-
标识符
Note
重用时可使用Declaration
Swift
public var identifier: String { get }
-
取值时去除了空格符以及换行符 可用于提交表单前用来判断值是否不为空
Declaration
Swift
public var contentText: String? { get set }
-
取值时去除了空格符以及换行符 可用于提交表单前用来判断值是否不为空
Declaration
Swift
public var contentText: String? { get set }
-
获取当前屏幕顶层ViewController
Declaration
Swift
public static func topViewController(of base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController?
Parameters
base
基础UIViewController,默认为window的rootViewController
-
是否可见
Declaration
Swift
public var isVisible: Bool { get }
-
删除所有子ViewController
Declaration
Swift
public func removeAllChildren()
-
dimiss所有的presentedViewController
Declaration
Swift
public func dismissToRootViewController(animated: Bool = true, completion: (() -> Void)? = nil)
Parameters
animated
是否显示动画
completion
完成dismiss闭包回调
-
生成提示框,一个按钮回调
Declaration
Swift
public static func getAlert(style: UIAlertController.Style = .alert, title: String = "", message: String, cancelTitle: String = "好的", sureBlock: (() -> Void)? = nil) -> UIAlertController?
Parameters
style
样式
title
标题
message
消息
cancelTitle
按钮标题
sureBlock
按钮闭包
-
显示提示框,一个按钮回调
Declaration
Swift
public func showAlert(style: UIAlertController.Style = .alert, title: String = "", message: String, cancelTitle: String = "好的", sureBlock: (() -> Void)? = nil)
Parameters
style
样式
title
标题
message
消息
cancelTitle
按钮标题
sureBlock
按钮闭包
-
生成提示框,两个按钮回调
Declaration
Swift
public static func getAlert(style: UIAlertController.Style = .alert, title: String = "", message: String, sureTitle: String = "确定", cancelTitle: String = "取消", cancelBlock: (() -> Void)? = nil, sureBlock: @escaping () -> Void) -> UIAlertController?
Parameters
style
样式
title
标题
message
内容
sureTitle
确定按钮标题
cancelTitle
取消按钮
sureBlock
确定按钮闭包回调
cancelBlock
取消按钮闭包回调
-
显示提示框,两个按钮回调
Declaration
Swift
public func showAlert(style: UIAlertController.Style = .alert, title: String = "", message: String, sureTitle: String = "确定", cancelTitle: String = "取消", cancelBlock: (() -> Void)? = nil, sureBlock: @escaping () -> Void)
Parameters
style
样式
title
标题
message
内容
sureTitle
确定按钮标题
cancelTitle
取消按钮
sureBlock
确定按钮闭包回调
cancelBlock
取消按钮闭包回调
-
点击空白处取消键盘
Declaration
Swift
public func hideKeyboardWhenTappedAround()
-
navigationBar高度
非刘海屏44;
Declaration
Swift
public var navigationBarHeight: CGFloat? { get }
-
tabBar高度
49;
Declaration
Swift
public var tabBarHeight: CGFloat? { get }
-
标识符
Declaration
Swift
public var identifier: String { get }
-
扩展 x 的 set get 方法
Declaration
Swift
public var x: CGFloat { get set }
-
扩展 y 的 set get 方法
Declaration
Swift
public var y: CGFloat { get set }
-
扩展 width 的 set get 方法
Declaration
Swift
public var width: CGFloat { get set }
-
扩展 height 的 set get 方法
Declaration
Swift
public var height: CGFloat { get set }
-
扩展 centerX 的 set get 方法
Declaration
Swift
public var centerX: CGFloat { get set }
-
扩展 centerY 的 set get 方法
Declaration
Swift
public var centerY: CGFloat { get set }
-
扩展 origin 的 set get 方法
Declaration
Swift
public var origin: CGPoint { get set }
-
扩展 size 的 set get 方法
Declaration
Swift
public var size: CGSize { get set }
-
扩展 left 的 set get 方法
Declaration
Swift
public var left: CGFloat { get set }
-
扩展 right 的 set get 方法
Declaration
Swift
public var right: CGFloat { get set }
-
扩展 top 的 set get 方法
Declaration
Swift
public var top: CGFloat { get set }
-
扩展 bottom 的 set get 方法
Declaration
Swift
public var bottom: CGFloat { get set }
-
移除键盘inputAccessoryView
Declaration
Swift
public func removeInputAccessoryView()