SPExtension

public struct SPExtension<Base>

Undocumented

  • Undocumented

    Declaration

    Swift

    public let base: Base
  • Undocumented

    Declaration

    Swift

    public init(_ base: Base)
  • 图片尺寸: Bytes

    Declaration

    Swift

    public var sizeAsBytes: Int { get }
  • 图片尺寸: KB

    Declaration

    Swift

    public var sizeAsKB: Int { get }
  • 图片尺寸: MB

    Declaration

    Swift

    public var sizeAsMB: Int { get }
  • 获取 base64 字符串

    Declaration

    Swift

    public func base64String(quality: CGFloat = 1.0) -> String?

    Parameters

    quality

    图片质量 用于JPEG, 默认为 1

    Return Value

    base64String

  • 返回一张没有被渲染图片

    Declaration

    Swift

    public var original: UIImage { get }
  • 返回圆形图片

    Declaration

    Swift

    public var roundImg: UIImage { get }
  • 裁剪对应区域

    Declaration

    Swift

    public func crop(bound: CGRect) -> UIImage

    Parameters

    bound

    裁剪区域

    Return Value

    新图

  • 图像处理: 裁圆

    • radius: 圆角大小
    • corners: 圆角区域
    • borderWidth: 描边大小
    • borderColor: 描边颜色
    • borderLineJoin: 描边类型

    Declaration

    Swift

    public func round(radius: CGFloat,
                      corners: UIRectCorner = .allCorners,
                      borderWidth: CGFloat = 0,
                      borderColor: UIColor? = nil,
                      borderLineJoin: CGLineJoin = .miter) -> UIImage

    Return Value

    新图

  • 根据宽度获取对应高度

    Declaration

    Swift

    func aspectHeight(with width: CGFloat) -> CGFloat

    Parameters

    width

    宽度

    Return Value

    新高度

  • 根据高度获取对应宽度

    Declaration

    Swift

    func aspectWidth(with height: CGFloat) -> CGFloat

    Parameters

    height

    高度

    Return Value

    宽度

  • 重设图片大小

    Declaration

    Swift

    public func reSize(size: CGSize) -> UIImage

    Parameters

    size

    新的尺寸

    Return Value

    新图

  • 根据宽度重设大小

    Declaration

    Swift

    public func resize(width: CGFloat) -> UIImage

    Parameters

    width

    宽度

    Return Value

    新图

  • 根据高度重设大小

    Declaration

    Swift

    public func resize(height: CGFloat) -> UIImage

    Parameters

    height

    高度

    Return Value

    新图

  • 等比率缩放

    Declaration

    Swift

    public func scale(multiple: CGFloat) -> UIImage

    Parameters

    multiple

    倍数

    Return Value

    新图

  • 压缩图片

    Declaration

    Swift

    public func compress(rate: CGFloat) -> Data?

    Parameters

    rate

    压缩比率

    Return Value

    新图

  • 改变字体大小 增加或者减少

    Declaration

    Swift

    public func change(font offSet: CGFloat)
  • 返回视图所在的视图控制器

    示例:

     let vc = UIView().sp.viewController
    

    Declaration

    Swift

    public var viewController: UIViewController? { get }
  • 视图中层级关系描述

    示例:

     <UIView; frame = (15 74; 345 201); autoresize = RM+BM; layer = <CALayer>>
     | <UIView; frame = (8 8; 185 185); autoresize = RM+BM; layer = <CALayer>>
     |    | <UIView; frame = (8 8; 169 76.5); autoresize = RM+BM; layer = <CALayer>>
     |    |    | <UIButton; frame = (8 8; 153 30); opaque = NO; autoresize = RM+BM; layer = <CALayer>>
     |    | <UIView; frame = (8 100.5; 169 76.5); autoresize = RM+BM; layer = <CALayer>>
     | <UIView; frame = (201 8; 136 185); autoresize = RM+BM; layer = <CALayer>>
     |    | <UILabel; frame = (8 8; 120 21); text = 'Label'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer>
    

    Declaration

    Swift

    public var description: String { get }
  • 获取视图显示内容

    示例:

     UIImageView(image: UIView().sp.snapshot)
    

    Declaration

    Swift

    public var snapshot: UIImage? { get }
  • 设置LayerShadow,offset,radius

    Declaration

    Swift

    public func setShadow(color: UIColor, offset: CGSize, radius: CGFloat)
  • 添加子控件

    示例:

     let aView = UIView()
     let bView = UIView()
     UIView().sp.addSubviews(aView,bView)
    

    Declaration

    Swift

    public func addSubviews(_ subviews: UIView...)

    Parameters

    subviews

    子控件数组

  • 移除全部子控件

    Declaration

    Swift

    public func removeSubviews()
  • 添加子控件

    示例:

     let tap = UITapGestureRecognizer(target: self, action: #selector(tapEvent(_:)))
     let pan = UIPanGestureRecognizer(target: self, action: #selector(tapEvent(_:)))
     UIView().addGestureRecognizers(tap,pan)
    

    Declaration

    Swift

    func addGestureRecognizers(_ gestureRecognizers: UIGestureRecognizer...)

    Parameters

    subviews

    手势对象数组

  • 移除全部手势

    Declaration

    Swift

    public func removeGestureRecognizers()
  • tabbarHeight高度

    Declaration

    Swift

    public var tabbarHeight: CGFloat { get }
  • 能否回退

    Declaration

    Swift

    public var canback: Bool { get }
  • 当前是控制器是否是被modal出来

    Declaration

    Swift

    public var isByPresented: Bool { get }
  • 是否是当前显示控制器

    Declaration

    Swift

    public var isVisible: Bool { get }
  • 前进至指定控制器

    Declaration

    Swift

    public func push(vc: UIViewController?, isRemove: Bool = false, animated: Bool = true)

    Parameters

    vc

    指定控制器

    isRemove

    前进后是否移除当前控制器

    animated

    是否显示动画

  • modal 指定控制器

    Declaration

    Swift

    func present(vc: UIViewController?, animated: Bool = true, completion: (() -> Void)? = nil)

    Parameters

    vc

    指定控制器

    animated

    是否显示动画

    completion

    完成后事件

  • 后退一层控制器

    Declaration

    Swift

    @discardableResult
    public func pop(animated: Bool) -> UIViewController?

    Parameters

    animated

    是否显示动画

    Return Value

    vc

  • 后退至指定控制器

    Declaration

    Swift

    @discardableResult
    public func pop(vc: UIViewController, animated: Bool) -> [UIViewController]?

    Parameters

    vc

    指定控制器

    animated

    是否显示动画

    Return Value

    vcs

  • 后退至根控制器

    Declaration

    Swift

    @discardableResult
    public func pop(toRootVC animated: Bool) -> [UIViewController]?

    Parameters

    animated

    是否显示动画

    Return Value

    vcs