ZSwiftBaseLib 0.1.6.2

ZSwiftBaseLib 0.1.6.2

zjc 维护。



  • zjc19891106

ZSwiftBaseLib

CI Status Version License Platform

示例

要运行示例项目,请克隆仓库,然后先从示例目录中运行 pod install

功能列表

UIKitSDL, UIView 及其子类可以使用,与 CALayerDSL 相同。

```
    Swift
    
    private lazy var logo: UIImageView = {
        UIImageView(frame: CGRect(x: ScreenWidth/3.0, y: ZNavgationHeight+20, width: ScreenWidth/3.0, height: ScreenWidth/3.0)).image(UIImage(named: "login_logo")!).contentMode(.scaleAspectFit)
    }()

    private lazy var userNameField: UITextField = {
        UITextField(frame: CGRect(x: 20, y: self.logo.frame.maxY+20, width: ScreenWidth - 40, height: 40)).cornerRadius(5).placeholder("UserName").delegate(self).tag(111).layerProperties(UIColor(0xf5f7f9), 1).leftView(UIView(frame: CGRect(x: 0, y: 0, width: 20, height: 40)), .always)
    }()

    private lazy var login: UIButton = {
        UIButton(type: .custom).frame(CGRect(x: 20, y: self.passWordField.frame.maxY+40, width: ScreenWidth - 40, height: 45)).backgroundColor(UIColor(0x0066ff)).cornerRadius(10).title("Login", .normal).font(UIFont.systemFont(ofSize: 18, weight: .semibold)).addTargetFor(self, action: #selector(loginAction), for: .touchUpInside)
    }()


    private lazy var logRecord: UITextView = {
        UITextView(frame: CGRect(x: 20, y: self.register.frame.maxY+20, width: ScreenWidth - 40, height: ScreenHeight - self.register.frame.maxY - 40)).layerProperties(UIColor(0xf5f7f9), 1).cornerRadius(5).font(UIFont.systemFont(ofSize: 18, weight: .semibold)).isEditable(false)
    }()
    
    private lazy var functionList: UITableView = {
        UITableView(frame: CGRect(x: 0, y: ZNavgationHeight, width: ScreenWidth, height: ScreenHeight-ZNavgationHeight), style: .plain).delegate(self).dataSource(self).tableFooterView(UIView()).rowHeight(50)
    }()

```

UIColorExtension,颜色十六进制和随机颜色

```
    Swift
    
    UIColor(0xaaaaaa)
    
    UIColor.randomColor
```

ArrayExtension,使用安全下标

```
    Swift
    
    [1,2,3][safe: 3] //prevent crash
    
    [1,2,3][safe: 0...3] //prevent crash
```

DataExtension,快速转换为 dictionary

```
    Swift
    
    Data().z.toDictionary()
```

DateExtension,方便操作日期

PropertyWrapper,方便进行某项操作,例如

```
    Swift
    
    @UserDefault("AgoraChatUserName", defaultValue: "") var userName
    
    @Default(0) var idx
    
    @CopyingProperty(NSObject()) var model// NSObject confirm NSCopying
    
    @Expirable(wrappedValue: "test", expirationDate: date, duration: 60)//60s
```

PlaceHolderTextView,可以设置占位符

NSAttributedStringFunctionBuilder,可以使用 NSAttributedString,例如

```
     self.attributeTextView.attributedText = NSAttributedString {
        AttributedText("一二三四五,上山打老虎,老虎不吃人,老虎屁股摸不得").font(.systemFont(ofSize: 14)).foregroundColor(.orange).lineSpacing(5)
        LineBreak()
        LineBreak()
        AttributedText("太阳当空照,花儿对我笑").font(.systemFont(ofSize: 16)).foregroundColor(.gray)
        LineBreak()
        Link("百度一下,你就知道", url: URL(string: "https://www.baidu.com")!)
    }
    
    func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
        if URL.absoluteString == "https://www.baidu.com" {
     return true
        } else {
            return false
        }
    }
```

StringExtension,方便操作字符串,例如

```
    Swift
    
    "123"[safe:4],"123"[safe:0...3],"1232"-="1"
    
    String.documentsPath or temp and cache
    
    "123".z.numCount
    
    "https://xxx.xxx.xxx".z.urlEncoded or urlDecoded
    
    "123".z.containEmoji
    
    "123".z.verticalText
    
    .z.rangOfSting
    
    .z.jsonToDictionary()
    
    .z.isMatchRegular("\a[0~9]")
    
    .z.toDate()
    
    .z.convertToTextImage
    
    .z.generateQRCode
    
    .z.md5
    
    .z.hexColor
```

DispatchExtension,方便使用,例如

```
    Swift
    
    DispatchQueue.once ("xxx") {
    
    }
    
    DispatchQueue.asyncTaskBackMainQueue(.global()) {
        <#code#>
    } mainSuccess: { <#_#> in
        <#code#>
    } mainError: { <#Error#> in
        <#code#>
    }
```

UIViewFunctionBuilder

```
    Swift
    
    let v = UIView {
        UIView()//must fill
        UIButton()
        UILabel()
    }
```

URLExtension,方便操作 URL

ViewMemoryStorage,指向指针或值

UIImageExtension,压缩或缩放

CircularMenuLayout,继承自 UICollectionFlowLayout 的环形菜单布局

需求

iOS 10.0

安装

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

pod 'ZSwiftBaseLib'

作者

zjc19891106, [email protected]

许可

ZSwiftBaseLib遵循MIT许可。有关更多信息,请参阅LICENSE文件。