Extension

0.9.2

A collection of extensions of Cocoa, for quick developing
DingSoung/Extension

What's New

2019-11-24T17:09:27Z

Release Status

SwiftPackage

Language Platform

Donate

简介

各种 Swift Extension 扩展合集

安装

  • Swift Package Manager *
"https://github.com/DingSoung/Extension", master

模块

Chainable 链式调用

let attrbuteString = NSMutableAttributedString(string: "hello")
    .foregroundColor(.red)
    .underlineColor(.blue)
    .underlineStyle(.single)

let label = UILabel()
    .backgroundColor(.white)
    .textAlignment(.center)
    .numberOfLines(2)
    .lineBreakMode(.byTruncatingMiddle)
    .attributedText(attrbuteString)

欢迎补充

  • UIView
  • UILabel
  • NSMutableAttributedString
  • NSMutableParagraph
  • CALayer

Color hex and css

let components = UIColor.red.components

let hex1 = UIColor.red.hex8

let hex2 = UIColor.red.hex8String

let color1 = Color.css("lemonchiffon")

let color3 = Color.hex("#777777")

let color3 = Color(hex8: 0xAABBCCDD)

let color4 = Color(red: 0, green: 127, blue: 255, alpha: 255)

Image

let image1 = Image.image(render: {
    let ovalPath = UIBezierPath(ovalIn: CGRect(x:0, y:0, width:5, height:5))
    UIColor.white.setFill()
    ovalPath.fill()
}, size: CGSize(width: 10, height: 10), opaque: true)

let image2 = Image.image(pdf: "ok",
                         bundle: UIBundle.main,
                         page: 0,
                         size: imageView.frame.size)

let image3 = originImage.image(scale: 0.8)

let image4 = originImage.image(ratio: 2)

let image5 = originImage.image(size: CGSize(width: 10, height: 20))

let image6 = originImage.image(radius: 5)

let image7 = originImage.roundImage

runtime

new selector

let button = UIButton()
let selector = selector(uid: view.hash.description, types: "v@:", classes: [UIView.self]) {
    print("cation")
}
button.addTarget(button, action: selector, for: .touchUpInside)
  • add selector

  • replace selector

  • exchange selector

  • get all methods

  • check exists selector in class

View

work with keyboard

let view = UIView()
view.keyboardInfoDidUpdateCallBack = { info in
    UIView.animate(withDuration: info.duration,
                   delay: 0,
                   options: info.option,
                   animations: {
                    view.frame.origin.y = info.frame.origin.y - 200
    }, completion: nil)
}

convert to image

let view = UIView()
let image = view.image(alpha: 0.8, bounds: view.bounds, scale: 0.5)

Dispatch once

DispatchQueue.main.once {
	print("hello")
}
  • userdefault

  • http cookie

  • CFAbsoluteTime

  • bundle localizationCode

  • Dictionary Array Data MIME Type

  • KeyChain

  • WKWebView keyboard

  • WKWebView protocol

  • URL query

  • Log

  • String Size

  • TableView to image

  • UINavigationController rota

Description

  • Swift Tools 5.0.0
View More Packages from this Author

Dependencies

  • None
Last updated: Tue Mar 19 2024 04:24:50 GMT-0900 (Hawaii-Aleutian Daylight Time)