Latest 1.3.4
License MIT
Platforms ios 9.0, requires ARC
Dependencies SnapKit
Frameworks UIKit, AVFoundation, Photos

Extensions, global functions for swift. Create a component with one line of codes.

10 times to improve your code efficiency.

Main Features!

  • Create a component with one line of codes, like a label, button, textField…
  • Use global functions instead of some Apple APIs.
  • Make many extensions and convenience init methods for UILabel/UIButton/UIView/UIViewController/UIImage…

    How To Install?


    Just drag the DJExtension folder to your project.

This is what all you should do, then you can use the extension functions. All the functions or constants are start with dj.


pod 'DJExtension'

You should also import this framework before you use it, like this import DJExtension.

The reason to use DJExtension

With DJExtension, you won’t need to write duplicate and redundant codes in your projects. Here are some examples.

Example 01 – create labels

  • before
    let label = UILabel()
    label.text          = "Label"
    label.font          = UIFont.systemFont(ofSize: 11)
    label.textColor     = UIColor(red: 123.0/255, green: 123.0/255, blue: 123.0/255, alpha: 1)
    label.textAlignment = .left
    label.numberOfLines = 1


label.snp.makeConstraints { (make) in

- now

UILabel(text: "Label", font: dj_systemfont(11), color: dj_rgbGrayColor(123), alignment: .left, lineCount: 1, superView: view) { (make) in

The parameter `alignment` and `lineCount` have default values, so you can also write like this.

UILabel(text: "Label", font: dj_systemfont(11), color: dj_rgbGrayColor(123), superView: view) { (make) in

#### Example 02 - create buttons
- before

let button = UIButton()
button.setTitle("On", for: .normal)
button.setTitle("Off", for: .selected)
button.titleLabel?.font = UIFont(name: "PingFangSC-Regular", size: 11)
button.setTitleColor(, for: .normal)
button.setTitleColor(, for: .selected)
button.backgroundColor = UIColor.white

button.addTarget(self, action: #selector(clickSwitch(button:)), for: .touchUpInside)


button.snp.makeConstraints { (make) in

- now

UIButton(title: "On", selTitle: "Off", titleFont: dj_pingRegularFont(11), titleColor: djGreen, selTitleColor: djRed, bgColor: djWhite, target: self, action: #selector(clickSwitch(button:)), superView: view) { (make) in

#### Example 03 - create text fileds
- before

let textField = UITextField()
textField.placeholder = "Please input your name"
textField.textColor =
textField.font = UIFont.systemFont(ofSize: 11)
textField.textAlignment = .left
textField.keyboardType = .default
textField.clearButtonMode = .always


textField.snp.makeConstraints { (make) in

- now

UITextField(placeholder: "Please input your name", placeholderColor: djLightGray, placeholderFont: dj_systemfont(11), textColor: djBlue, superView: view) { (make) in

###### Note
You can set the placeholder color and placeholder font for your text filed with DJExtension.
#### Example 04 - push a new view controller
- before

navigationController?.pushViewController(TestViewController(), animated: true)

- now


#### Example 05 - show an action sheet
- before

let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)

let action1 = UIAlertAction(title: "Take a photo", style: .default) { (action) in
print("Take a photo")
let action2 = UIAlertAction(title: "Open photo library", style: .default) { (action) in
print("Open photo library")
let action3 = UIAlertAction(title: "Cancel", style: .cancel)


present(alertController, animated: true, completion: nil)

- now

djshowActionSheet(firstTitle: "Take a photo", firstAction: { () in
print("Take a photo")
}, secondTitle: "Open photo library") { (_) in
print("Open photo library")

###### Note:
You can also set color for the action titles with DJExtension.
### More functions you may use
| Functions | Comment |
| ------ | ------ |
|`dj_hexColor("00ff00")`|get a color with a hex value.
|`dj_pingSemiboldFont(15)`|get a font from the font family "PingFangSC-Semibold".
|`dj_isCameraAllowed()`|the camera authorization is allowed or not.
|`dj_navigationBarHeight()`|get the navigation bar height(adapted iPhone X or later).
|`dj_isEmpty(obj)`|an object is empty or not.
|`dj_isIPhoneX()`|the phone is iPhone X,Xs,Xs Max or not.
|`dj_toJson(obj)`|convert an object to json string.
|`dj_callPhone("13288889990")`|call a number
|`dj_saveFile(url, fileName)`|save a file to sandbox.
|`dj_deleteFile(fileName)`|delete the file from sandox.
|`dj_postNotification("LoginSuccessNotification")`|post a notification.
###### Note:
You can find more global functions in file `DJGlobalFunctions.swift`.
### License
### Contact Me

###### Thanks

Latest podspec

    "name": "DJExtension",
    "version": "1.3.4",
    "summary": "Extensions and globalFunctions for swift. Create components with one line of code.",
    "homepage": "",
    "license": "MIT",
    "platforms": {
        "ios": "9.0"
    "swift_version": "4.2",
    "authors": {
        "jiadawei": "[email protected]"
    "source": {
        "git": "",
        "tag": "1.3.4"
    "source_files": "DJExtension/**/*.{swift}",
    "requires_arc": true,
    "frameworks": [
    "dependencies": {
        "SnapKit": []

Pin It on Pinterest

Share This