CWUtils 1.1.1

CWUtils 1.1.1

Ryan Song 维护。



 
依赖项
RxSwift>= 0
RxCocoa>= 0
RxSwiftExt>= 0
RxOptional>= 0
然后>= 0
RxViewController>= 0
SnapKit>= 0
Panda>= 0
可复用>= 0
Kingfisher>= 0
 

CWUtils 1.1.1

  • 作者:
  • iamchiwon

CWUtils

Version License Platform

安装

Cocoapods

CWUtils 可以通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile 中

pod 'CWUtils'

Swift 包管理器

将目标与正确的产品匹配

依赖项

示例代码

实用工具

日志

DLog("log for debug build only")
ELog("error log for all build")

设备

runOnSimulatorOnly {
    print("running on simulator")
}
runOnDeviceOnly {
    print("running on device")
}

版本检查

let currentVersion: String = currentApplicationVersion()
let needUpdate: Bool = isUpdateAvailable()

验证

let isEmail = "[email protected]".isValid(withType: .email)
let isEmail2 = "[email protected]".isValid(withRegEx: "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}")

扩展

字符串

let url = "www.apple.com".url()
let base64 = "hello world".base64()
let trimmed = "   hello world   \n \n    ".trim()
let localized = "Hello World".localized()

日期

let serverDateParser = Date.fromFormat("yyyy-MM-dd HH:mm:ss")
let date = serverDateParser("2018-02-17 17:00:00")

数组

struct Data : Equatable {}
var array: [Data]
//--------
let data = Data()
let exists: Bool = array.exists(data)
let index: Int = array.indexOf(data)
let array2 = array.removed(data)
array.remove(item: data) //mutating

编码

struct Data : Codable {}
//--------
let data = Data()
let dictionary: [String:Any] = data.dictionary()
let jsonString: String = data.json()
let jsonString2: String = dictionary.json()
let data2: Data = dictionary.decode()

用户界面

UIColor

let red = UIColor(red:255, green:0, blue:0)
let blue = UIColor(0x00FF00)
let green = UIColor("#0000FF")

子视图

//view with tag
view.label(100)?.text = "Hello World"
//image with tag
view.imageView(100)?image = nil

弹出窗口

if needUpdate {
    popupOkCancel(on: self, title: "업데이트", message: "업데이트가 필요합니다.", onOk: {
        let urlString = "itms-apps://itunes.apple.com/app/id0000000000"
        UIApplication.shared.openURL(URL(string: urlString)!)
    })
} else {
    popupOK(on: self, title: "업데이트", message: "최신버전입니다.")
}

图像调整大小

let original = UIImage(named: "big_image")
let resized = original?.resized(maxSize: CGSize(width: 100, height: 100))
let resizedForScreen = original?.resizedToScreen()

使用SnapKit查看创建者

let rect = createView(UIView(), parent: self.view, setting: { v in
            v.backgroundColor = .red
        }, constraint: { m in
            m.top.left.equalToSuperview()
            m.width.height.equalTo(100)
        })

RxSwift

手势识别器

view.addTapGestureRecognizer()
    .subscribe(onNext: { (tapGusture : UITapGestureRecognizer) in
    })

view.addSwipeGestureRecognizer()
    .subscribe(onNext: { (tapGusture : UISwipeGestureRecognizer) in
    })

按钮

//prevent double touched
view.button(100)?.whenTouchUpInside(thro)
    .subscribe(onNext: { button in
    })

键盘通知

whenKeyboardShowNotification()
    .subscribe(onNext: { (keyboardHeight: CGFloat, duration: TimeInterval) in
    })
    .disposed(by: disposeBag)

whenKeyboardHideNotification()
    .subscribe(onNext: { (duration: TimeInterval) in
    })
    .disposed(by: disposeBag)

滚动视图

collectionView.needsMore()
	.filter { !self.isLoading }
	.subscribe(onNext: { self.loadMore() })
	.disposed(by: disposeBag)

图片选择器

pickImageFromAlbum(on: self, withEdit: true)
    .subscribe(onNext: {  self.imageView.image = $0 })

作者

iamchiwon, [email protected]

许可证

CWUtils 项目可在 MIT 许可证下使用。有关更多信息,请参阅 LICENSE 文件。