Latest0.0.9
Homepagehttps://github.com/qianshang/UIKitExtSwift
LicenseMIT
Platformsios 8.0
Authors

UIKit extension of swift

预览图片

UIColor

// 使用UInt32创建颜色
UIColor(0xFF0000)
UIColor(0xFF0000, 1)
0xFF0000.ex.color

// 获取颜色的16进制描述
UIColor.red.hexString

UIImage

// 使用指定颜色创建图片
UIImage.ex.color(with: .blue, size: size, storkColor: .red, storkWidth: 10, radius: 50)
// 创建线性渐变色图片
UIImage.ex.linerGradient(colors: colors, size: size)
// 生成一张二维码
try! UIImage.ex.qrcode(with: "UIKitExtSwift", size: size)
// 修改图片大小                             
image.ex.resize(size)
// 获取指定区域的图片
image.ex.subImage(rect)
// 两张图片合成
image.ex.add(flagImage)
// 指定半径和边角裁剪
image.ex.clip(5)
// 将图片渲染成指定颜色
image.ex.render(.gray)

UIButton

public enum ImageDirection {
    case left(distance: CGFloat)
    case right(distance: CGFloat)
    case top(distance: CGFloat)
    case bottom(distance: CGFloat)
}

// 指定`UIButton`图片方向以及和文字间的间距
btn.ex.imageDirection = .top(distance: 5)

UIView

public var x: CGFloat
public var midX: CGFloat
public var maxX: CGFloat
public var y: CGFloat
public var midY: CGFloat
public var maxY: CGFloat
public var origin: CGPoint
public var size: CGSize
public var width: CGFloat
public var height: CGFloat
public var touchEdgeInsets: UIEdgeInsets
public func snapshot() -> UIImage?
public func shadow(color: UIColor = .gray,
                       offsetX: CGFloat = 3,
                       offsetY: CGFloat = 3,
                       radius: CGFloat = 1,
                       opacity: Float = 1) -> UIView

let v: UIView = UIView()
v.ex.touchEdgeInsets = UIEdgeInsetsMake(-20, -20, -20, -20)
v.ex.shadow()
v.ex.snapshot()

UIApplication

// 直接通过UIApplication.shared实例获取当前栈顶控制器
UIApplication.shared.ex.currentViewController?

UIControl

使用closureUIControl对象添加事件处理
当前支持通过这种方式添加的事件如下:

  • ouchDown
  • touchDownRepeat
  • touchDragInside
  • touchDragOutside
  • touchDragEnter
  • touchDragExit
  • touchUpInside
  • touchUpOutside
  • touchCancel
  • valueChanged
  • allEvents
// 给按钮添加`touchDown`事件
btn.ex.touchDown { _ in
   print("btn clicked")
}

UIDevice

let iPhoneX: Bool = UIDevice.current.ex.deviceType == .iPhoneX

Cocoapods

pod 'UIKitExtSwift'

TODO

  • ✓ 使用IntUInt32创建UIColor
  • ✓ 获取UIColor的16进制描述
  • ✓ 使用指定颜色创建图片
  • ✓ 重置图片大小
  • ✓ 获取指定区域的图片
  • ✓ 将图片渲染成指定颜色
  • ✓ 生成一张二维码图片
  • ✓ 生成线性渐变图片
  • ✓ 设置按钮图片位置
  • ✓ 使用闭包为按钮添加事件处理 此处没有找到特别好的方法,所以直接添加了部分event事件支持
  • UIView的位置相关信息
  • UIView点击区域扩充
  • ✓ 当前设备判断
  • UITextView添加placeholder

Latest podspec

{
    "name": "UIKitExtSwift",
    "version": "0.0.9",
    "summary": "A short description of UIKitExtSwift.",
    "homepage": "https://github.com/qianshang/UIKitExtSwift",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "ChengWei": "[email protected]"
    },
    "source": {
        "git": "https://github.com/qianshang/UIKitExtSwift.git",
        "tag": "0.0.9"
    },
    "source_files": "UIKitExtSwift/**/*.swift",
    "platforms": {
        "ios": "8.0"
    }
}

Pin It on Pinterest

Share This