CSSwiftExtension 0.2.0

CSSwiftExtension 0.2.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2019年4月
SPM支持 SPM

Chris Hu维护。



  • 作者:
  • Chris Hu

CSSwiftExtension

Build Status Cocoapods Carthage compatible Platform Swift Xcode MIT

一些 有用的 Swift 扩展,可提升您的工作效率。

要求

Xcode 8(或更高版本)以及 Swift 3。此库是为 iOS 8 或更高版本而设计的。

安装

CocoaPods

CocoaPods 是 Cocoa 项目的依赖关系管理器。您可以使用以下命令安装它

$ gem install cocoapods

要使用 CocoaPods 将 CSSwiftExtension 集成到您的 Xcode 项目中,请在您的 Podfile 中指定它

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'CSSwiftExtension'
end

然后,运行以下命令

$ pod install

Carthage

Carthage 是一个去中心化的依赖管理器,可构建您的依赖并提供二进制框架。

您可以使用以下命令使用 Homebrew 安装Carthage:

$ brew update
$ brew install carthage

要使用 Carthage 将 CSSwiftExtension 集成到您的 Xcode 项目中,请在您的 Cartfile 中指定它。

github "icetime17/CSSwiftExtension"

运行 carthage update 构建框架,然后将构建的 CSSwiftExtension.framework 文件拖放到 Xcode 项目中 /Carthage/Build/iOS 文件夹。

手动

文件夹添加到您的 Xcode 项目中,以使用所有扩展或特定扩展。

使用方法

Foundation

字符串扩展

let string = " hello 17, this is my city "
let a = string.cs_trimmed
let b = string.cs_length
aNonUTF8String.cs_utf8String

let regExp_email = "^[a-zA-Z0-9]{1,}@[a-zA-Z0-9]{1,}\\.[a-zA-Z]{2,}$"
cs_validateWithRegExp(regExp: regExp_email)

数组扩展

[1, 5, 10].cs_sum
["a", "b", "c", "a", "c"].cs_removeDuplicates()

UIKit

UIApplication 扩展

UIApplication.shared.cs.appVersion
UIApplication.shared.cs.currentViewController

UIColor 扩展

imageView.backgroundColor = UIColor(hexString: 0x123456, alpha: 0.5)
imageView.backgroundColor = UIColor.cs.random

UIImage 扩展

guard let image = UIImage(named: "Model.jpg") else { return }
let a = image.cs.imageMirrored
let b = image.cs.imageCropped(bounds: CGRect(x: 0, y: 0, width: 200, height: 200))
let c = image.cs.imageWithNormalOrientation
let d = image.cs.imageRotatedByDegrees(degrees: 90)
let e = image.cs.imageWithCornerRadius(cornerRadius: 100)
let f = image.cs.imageScaledToSize(targetSize: CGSize(width: 300, height: 300), withOriginalRatio: true)
let g = image.cs.wechatShareThumbnail
let h = image.cs.grayScale

// Thanks to https://github.com/bahlo/SwiftGif for gif support
aImageView.loadGif(name: "Railway")
aImageView.image = UIImage.gif(name: "Railway")

UIView 扩展

imageView.cs.snapShot()
let aView = AView.cs.loadFromNib("AView") as? AView
aView.setCornerRadius(radius: 20)
aView.setCornerRadius(corners: [.bottomLeft, .bottomRight], radius: 20)

UIImageView 扩展

let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 300, height: 500), blurEffectStyle: .light)

UITableView 扩展

aTableView.cs.removeEmptyFooter()
aTableView.cs.scrollToTop(animated: true)

tableView.cs_register(MyTableViewCell.self)
let cell = tableView.cs_dequeueReusableCell(forIndexPath: indexPath) as MyTableViewCell

UIButton 扩展

btnTest.cs_acceptEventInterval = 2 // to avoid UIButton's multiple click operation
btnTest.cs.setBackgroundColor(UIColor.blue, for: .normal) // set backgroundColor
btnTest.cs.setBackgroundColor(UIColor.red, for: .highlighted)

CGPoint 扩展

aPoint.cs_distance(toPoint: bPoint)
CGPoint.cs_distance(fromPoint: aPoint, toPoint: bPoint)

DispatchQueue 扩展

DispatchQueue.cs.delay(2) {
    print("delay action")
}
DispatchQueue.cs.global {
    print("global action")
    DispatchQueue.cs.main {
        print("main action")
    }
}

联系

如果你发现任何问题,请提出工单。拉的请求也是欢迎的。

许可证

CSSwiftExtension 在 MIT 许可下发布。有关详细信息,请参阅 LICENSE.md。