TxExtensionWrapper
public struct TxExtensionWrapper<Base>
扩展命名空间
-
泛型
Declaration
Swift
public let base: Base -
构造函数
Declaration
Swift
public init(_ base: Base)Parameters
base泛型
-
通过Xcode视图调试工具找到UIBarButtonItem的Badge所在父视图为:UIImageView
Declaration
Swift
public var badgeContainerView: UIView { get }
-
通过Xcode视图调试工具找到UITabBarItem原生Badge所在父视图
Declaration
Swift
public var containerView: UIView { get }
-
Undocumented
Declaration
Swift
public func set(type: BadgeType) -
角标view
Declaration
Swift
public var badgeView: BadgeControl { get } -
设置Badge伸缩的方向
Declaration
Swift
public func set(flexMode: BadgeViewFlexMode = .tail)Parameters
flexMode伸缩方向,默认为 tail
-
设置Badge的高度,因为Badge宽度是动态可变的,通过改变Badge高度,其宽度也按比例变化,方便布局 (注意: 此方法需要将Badge添加到控件上后再调用!!!)
Declaration
Swift
public func set(height: CGFloat)Parameters
height高度大小
-
设置Badge的偏移量, Badge中心点默认为其父视图的右上角
Declaration
Swift
public func move(x: CGFloat, y: CGFloat)Parameters
xX轴偏移量 (x<0: 左移, x>0: 右移)
yY轴偏移量 (y<0: 上移, y>0: 下移)
-
延时扩展
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
bundleNamebundleName
podNamepodName,当使用framwork时使用,如果为nil,赋值为bundleName
-
16进制Data转字符串
Note
获取的推送token可以用这个进行转换Declaration
Swift
public var hexString: String { get }
-
Date格式化
Declaration
Swift
public func formatDate(format: DateFormateType) -> StringParameters
format格式化类型
Return Value
格式化后的字符串
-
Date格式化
Declaration
Swift
public func formatDate(formatStr: String) -> StringParameters
format日期格式
Return Value
格式化后的字符串
-
获取星期
Declaration
Swift
public var weekDay: String { get } -
获取相对指定时间之前几天或者之后几天的日期,之前的填入负数
Declaration
Swift
public func getDateByDays(days: Int) -> DateParameters
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) -> StringParameters
format时间格式化格式
-
时间戳(秒)转时间
Declaration
Swift
public var dateAsTimeStamp: Date { get } -
时间戳(秒)转时间字符串
Declaration
Swift
public func toDateStrAsTimeStamp(format: DateFormateType) -> StringParameters
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 : EquatableParameters
repeated去重标准
-
keyPath的形式对数组排序
Declaration
Swift
public func sorted<T>(by keyPath: KeyPath<Base.Iterator.Element, T>) -> [Base.Iterator.Element] where T : ComparableParameters
keyPathkeyPath
Return Value
排序后的数组
-
将集合分组
Declaration
Swift
public func group<GroupingType>(by key: (Base.Iterator.Element) -> GroupingType) -> [[Base.Iterator.Element]] where GroupingType : HashableParameters
key分组依据
Return Value
分组后结果
-
删除指定前缀
Declaration
Swift
public func deletingPrefix(_ prefix: String) -> StringParameters
prefix前缀
Return Value
删除后的字符串
-
删除指定后缀
Declaration
Swift
public func deletingSuffix(_ suffix: String) -> StringParameters
suffix后缀
Return Value
删除后的字符串
-
截取字符串前指定位,异常情况返回原字符串
Declaration
Swift
public func getPrefix(count: Int) -> StringParameters
count位数值
Return Value
截取后的字符串
-
截取字符串后几位,异常情况返回原字符串
Declaration
Swift
public func getSuffix(count: Int) -> StringParameters
count位数值
Return Value
截取后的字符串
-
截取字符串,0位开始,左闭右开
Declaration
Swift
public func getSubString(start: Int, end: Int) -> StringParameters
start起始位
end终止位
Return Value
截取后的字符串
-
时间转日期
Declaration
Swift
public func toDate(dateType: DateFormateType, timeZone: TimeZone = TimeZone.current) -> Date?Parameters
dateType日期类型
Return Value
日期
-
时间转日期
Declaration
Swift
public func toDate(dateTypeStr: String, timeZone: TimeZone = TimeZone.current) -> Date?Parameters
dateType日期类型格式
Return Value
日期
-
截取时间字符串中的某一部分
Declaration
Swift
public func getDateStr(dateType: DateFormateType) -> StringParameters
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 var pinyin: String { get }Return Value
拼音
-
字符串转为类,限制主工程代码使用
Declaration
Swift
public var classOfMainBundle: AnyClass? { get } -
转为编码类型
Declaration
Swift
public var encodingType: String.Encoding? { 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) -> CGFloatParameters
font字体
width宽度
-
获取指定高度、字体的字符串宽度
不是绝对准确
Declaration
Swift
public func width(font: UIFont, height: CGFloat) -> CGFloatParameters
font字体
height高度
-
转为富文本
Declaration
Swift
public var attributedString: NSMutableAttributedString { get }
-
添加字体
Declaration
Swift
public func addFontStyle(fontName: String = "", fontStyle: FontStyle, fontSize: CGFloat) -> NSMutableAttributedStringParameters
fontName字体名称
fontStyle字体样式
fontSize字体尺寸
-
添加下划线
Declaration
Swift
public func addUnderline(style underlineStyle: NSUnderlineStyle = .single, color underlineColor: UIColor? = nil) -> NSMutableAttributedStringParameters
underlineStyle下划线样式,默认为single
underlineColor下划线颜色,默认为nil,nil时跟字体颜色保持相同
-
添加删除线
Declaration
Swift
public func addStrikethrough(style strikethroughStyle: NSUnderlineStyle = .single, color strikethroughColor: UIColor? = nil) -> NSMutableAttributedStringParameters
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) -> UIColorParameters
colorWithDark暗黑模式下的颜色,默认为nil,取颜色反色
-
适配各种模式
Declaration
Swift
public func adapt(colorWithDark: UIColor? = nil) -> UIColorParameters
colorWithDark暗黑模式颜色
-
粗体
Declaration
Swift
public static func boldFont(name fontName: String = "", size fontSize: CGFloat) -> UIFontParameters
fontName字体名称,为空时使用系统字体,默认为空
fontSize字体尺寸
-
斜体
Declaration
Swift
public static func italicFont(name fontName: String = "", size fontSize: CGFloat) -> UIFontParameters
fontName字体名称,为空时使用系统字体,默认为空
fontSize字体尺寸
-
粗体、斜体 如果粗体生成失败,则会返回斜体
Declaration
Swift
public static func boldItalicFont(name fontName: String = "", size fontSize: CGFloat) -> UIFontParameters
fontName字体名称,为空时使用系统字体,默认为空
fontSize字体尺寸
-
压缩图片 注意压缩后含有透明背景图片的背景会变成白色
Declaration
Swift
public func compress(type: ImageCompressType = .timeline) -> UIImageParameters
type压缩类型
Return Value
压缩后的图片
-
设置图片尺寸
Declaration
Swift
public func setSize(reSize: CGSize) -> UIImageParameters
reSize图片尺寸
Return Value
处理后的图片
-
缩放图片
Declaration
Swift
public func scaleImage(scaleSize: CGFloat) -> UIImageParameters
scaleSize缩放比例
Return Value
缩放后的图片
-
设置图片尺寸 宽度固定,高度按照原始尺寸
Declaration
Swift
public func resize(width: CGFloat, scale: CGFloat = 0) -> UIImageParameters
width宽度
scale放大倍数,0表示使用当前屏幕像素
Return Value
处理好的图片
-
设置图片尺寸 高度固定,宽度按照原始比例
Declaration
Swift
public func resize(height: CGFloat, scale: CGFloat = 0) -> UIImageParameters
height高度
scale放大倍数,0表示使用当前屏幕像素
Return Value
处理好的图片
-
压缩到指定尺寸以下
Declaration
Swift
public func compressOriginalImage(toBytes: Int) -> Data?Parameters
toBytes字节数
Return Value
压缩后的data,如果压缩失败或者压缩到最小压缩率还不到要求,则返回nil
-
图片旋转
Declaration
Swift
public func rotate(orientation: UIImage.Orientation) -> UIImageParameters
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图片名称
bundleNamebundleName
podNamepodName,当使用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() -
使html autofocus 属性生效,而不需要用户手动点击 Stack Overflow上可以设置开关,经过设置,如果value设置为true,input输入框都无法点击弹出键盘了 注意检查有没有副作用
Declaration
Swift
public func setKeyboardDisplayDoesNotRequireUserAction()
View on GitHub
TxExtensionWrapper Structure Reference