ADVHelper
Requirements
iOS 12.0 or above
Installation
ADVHelper is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'ADVHelper'
Usage
- ADVHelper
Using ADVHelper programmatically
Import ADVHelper at the top of each Swift file that will be used.
import ADVHelper
- Localize
Using Localize programmatically
Add .localized()
following any String
object you want translated:
let _ = "String".localized()
To change the current language:
Localize.setCurrentLanguage("th")
To update the UI in the view controller where a language change can take place, observe LCLLanguageChangeNotification:
NotificationCenter.default.addObserver(self, selector: #selector(setText), name: NSNotification.Name(LCLLanguageChangeNotification), object: nil)
Example function setText()
@objc func setText() {
titleLabel.localizeKey = "String".localized()
textFieldBox.localizeKey = "String".localized()
textViewBox.localizeKey = "String".localized()
buttonBtn.localizeKey = "String".localized()
}
- String Extension
Using String Extension programmatically
- DateFormatter
- Function
dateFormat
for set outputformat
In this function, it supports the input formats yyyy-MM-dd HH: mm: ss
and yyyy-MM-dd
. And default local date for input en
. And local date for output are based on Localize Language
.
Example input date
let inputDateStr = "2020-06-17 10:20:30"
Example of use
titleLabel.text = inputDateStr.dateFormat(format: "dd/MM/yyyy HH:mm")
Output
17/06/2020 10:20
- Function
dateFormat
for setfromFormat
andtoFormat
In this function, it default local date for input en
. And local date for output are based on Localize Language
.
Example input date
let inputDateStr = "2020-06-17 10:20:30"
Example of use
titleLabel.text = inputDateStr.dateFormat(fromFormat: "yyyy-MM-dd HH:mm:ss", toFormat: "dd/MM/yyyy HH:mm")
Output
17/06/2020 10:20
- Function
dateFormat
for setfromFormat
toFormat
andtoLocaleIdentifier
In this function, it default local date for input en
.
Example input date
let inputDateStr = "2020-06-17 10:20:30"
Example of use
titleLabel.text = inputDateStr.dateFormat(fromFormat: "yyyy-MM-dd HH:mm:ss", toFormat: "dd/MM/yyyy HH:mm", toLocaleIdentifier: "th")
Output
17/06/2563 10:20
- Function
dateFormat
for all setfromFormat
fromLocaleIdentifier
toFormat
andtoLocaleIdentifier
Example input date
let inputDateStr = "2563-06-17 10:20:30"
Example of use
titleLabel.text = inputDateStr.dateFormat(fromFormat: "yyyy-MM-dd HH:mm:ss", fromLocaleIdentifier: "th", toFormat: "dd/MM/yyyy HH:mm", toLocaleIdentifier: "en")
Output
17/06/2020 10:20
- Button
Using Button programmatically
Connect the UI to Code
@IBOutlet weak var buttonBtn: Button!
- Localize
Define text with localizeKey
buttonBtn.localizeKey = "Button".localized()
- Loading
To show a loader inside the button, and enable or disable user interection while loading
buttonBtn.showLoader()
To hide a loader
buttonBtn.hideLoader()
Using Button in Storyboard
The steps for use
- Drag a UIButton into Storyboard.
- Set class to
Button
- Set up attributes inspection.
- Border
Parameter | Type | Description | Default |
---|---|---|---|
borderColor | UIColor | The color of the layer’s border. | UIColor.clear |
borderWidth | CGFloat | The width of the layer’s border. | 0 |
- Corner Radius
Parameter | Type | Description | Default |
---|---|---|---|
cornerRadius | CGFloat | The radius to use when drawing rounded corners for the layer’s background. | 0 |
- Shadow
Parameter | Type | Description | Default |
---|---|---|---|
shadowColor | UIColor | The color of the layer’s shadow. | UIColor.clear |
shadowOpacity | Float | The opacity of the layer’s shadow. | 0 |
shadowOffset | CGSize | The offset (in points) of the layer’s shadow. | CGSize.zero |
shadowRadius | CGFloat | The blur radius (in points) used to render the layer’s shadow. | 0 |
- Gradient Background
Parameter | Type | Description | Default |
---|---|---|---|
gradientEnabled | Bool | Enable gradient background. | false |
gradientStartColor | UIColor | Start color gradient background. | UIColor.clear |
gradientEndColor | UIColor | End color gradient background. | UIColor.clear |
gradientHorizontal | Bool | Is the horizontal gradient background. | false |
- Click Animate
Parameter | Type | Description | Default |
---|---|---|---|
animatedScaleWhenHighlighted | CGFloat | Animation scale when highlighted. | 1.0 |
animatedScaleDurationWhenHighlighted | Double | Animation scale duration when highlighted. | 0.2 |
- Ripple
Parameter | Type | Description | Default |
---|---|---|---|
ripple | Bool | Enable ripple animation. | false |
rippleColor | UIColor | The color of the ripple animation. | UIColor(white: 1.0, alpha: 0.3) |
rippleSpeed | Double | The speed of the ripple animation. | 1.0 |
- Image
Parameter | Type | Description | Default |
---|---|---|---|
imageViewContentMode | Int | Options to specify how a view adjusts its content when its size changes. * ContentMode | 0 |
imageAlpha | CGFloat | The image view's alpha value. | 1.0 |
- Underline
Parameter | Type | Description | Default |
---|---|---|---|
isUnderline | Bool | Enable underline. | false |
- Label
Using Label programmatically
Connect the UI to Code
@IBOutlet weak var titleLabel: Label!
- Localize
Define text with localizeKey
titleLabel.localizeKey = "Label".localized()
Using Label in Storyboard
The steps for use
- Drag a UILabel into Storyboard.
- Set class to
Label
- Set up attributes inspection.
- Border
Parameter | Type | Description | Default |
---|---|---|---|
borderColor | UIColor | The color of the layer’s border. | UIColor.clear |
borderWidth | CGFloat | The width of the layer’s border. | 0 |
- Corner Radius
Parameter | Type | Description | Default |
---|---|---|---|
cornerRadius | CGFloat | The radius to use when drawing rounded corners for the layer’s background. | 0 |
- Shadow
Parameter | Type | Description | Default |
---|---|---|---|
shadowColor | UIColor | The color of the layer’s shadow. | UIColor.clear |
shadowOpacity | Float | The opacity of the layer’s shadow. | 0 |
shadowOffset | CGSize | The offset (in points) of the layer’s shadow. | CGSize.zero |
shadowRadius | CGFloat | The blur radius (in points) used to render the layer’s shadow. | 0 |
- Underline
Parameter | Type | Description | Default |
---|---|---|---|
isUnderline | Bool | Enable underline. | false |
- TextField
Using TextField programmatically
Connect the UI to Code
@IBOutlet weak var textFieldBox: TextField!
- Localize
Define placeholder with localizeKey
textFieldBox.localizeKey = "Placeholder".localized()
Using TextField in Storyboard
The steps for use
- Drag a UITextField into Storyboard.
- Set class to
TextField
- Set up attributes inspection.
- Border
Parameter | Type | Description | Default |
---|---|---|---|
borderColor | UIColor | The color of the layer’s border. | UIColor.clear |
borderWidth | CGFloat | The width of the layer’s border. | 0 |
- Corner Radius
Parameter | Type | Description | Default |
---|---|---|---|
cornerRadius | CGFloat | The radius to use when drawing rounded corners for the layer’s background. | 0 |
- Shadow
Parameter | Type | Description | Default |
---|---|---|---|
shadowColor | UIColor | The color of the layer’s shadow. | UIColor.clear |
shadowOpacity | Float | The opacity of the layer’s shadow. | 0 |
shadowOffset | CGSize | The offset (in points) of the layer’s shadow. | CGSize.zero |
shadowRadius | CGFloat | The blur radius (in points) used to render the layer’s shadow. | 0 |
- Gradient Background
Parameter | Type | Description | Default |
---|---|---|---|
gradientEnabled | Bool | Enable gradient background. | false |
gradientStartColor | UIColor | Start color gradient background. | UIColor.clear |
gradientEndColor | UIColor | End color gradient background. | UIColor.clear |
gradientHorizontal | Bool | Is the horizontal gradient background. | false |
- Padding
Left: 0, Right: 0 | Left: 8, Right: 0 | Left: 0, Right: 8 | Left: 8, Right: 8 |
---|---|---|---|
![]() |
![]() |
![]() |
![]() |
Parameter | Type | Description | Default |
---|---|---|---|
paddingLeftCustom | CGFloat | Pads the view along left edges by the specified amount. | 8 |
paddingRightCustom | CGFloat | Pads the view along right edges by the specified amount. | 8 |
- TextView
Using TextView programmatically
Connect the UI to Code
@IBOutlet weak var textViewBox: TextView!
- Localize
Define placeholder with localizeKey
textViewBox.localizeKey = "Placeholder".localized()
Using TextView in Storyboard
The steps for use
- Drag a UITextView into Storyboard.
- Set class to
TextView
- Set up attributes inspection.
- Border
Parameter | Type | Description | Default |
---|---|---|---|
borderColor | UIColor | The color of the layer’s border. | UIColor.clear |
borderWidth | CGFloat | The width of the layer’s border. | 0 |
- Corner Radius
Parameter | Type | Description | Default |
---|---|---|---|
cornerRadius | CGFloat | The radius to use when drawing rounded corners for the layer’s background. | 0 |
- Maximum length
Parameter | Type | Description | Default |
---|---|---|---|
maxLength | Int | The maximum character length. (0 means no limit) | 0 |
- Trim
Parameter | Type | Description | Default |
---|---|---|---|
trimWhiteSpaceWhenEndEditing | Bool | Trim whitespace and newline characters when end editing. | true |
- Height
Parameter | Type | Description | Default |
---|---|---|---|
minHeight | CGFloat | The minimum height limit. (0 means no limit) | 0 |
maxHeight | CGFloat | The maximum height limit. (0 means no limit) | 0 |
- Padding
Parameter | Type | Description | Default |
---|---|---|---|
paddingLeftCustom | CGFloat | Pads the view along left edges by the specified amount. | 8 |
paddingRightCustom | CGFloat | Pads the view along right edges by the specified amount. | 8 |
paddingTopCustom | CGFloat | Pads the view along top edges by the specified amount. | 8 |
paddingBottomCustom | CGFloat | Pads the view along bottom edges by the specified amount. | 8 |
- ImageView
Using ImageView programmatically
Connect the UI to Code
@IBOutlet weak var imageView: ImageView!
Using ImageView in Storyboard
The steps for use
- Drag a UIImageView into Storyboard.
- Set class to
ImageView
- Set up attributes inspection.
- Border
Parameter | Type | Description | Default |
---|---|---|---|
borderColor | UIColor | The color of the layer’s border. | UIColor.clear |
borderWidth | CGFloat | The width of the layer’s border. | 0 |
- Corner Radius
Parameter | Type | Description | Default |
---|---|---|---|
cornerRadius | CGFloat | The radius to use when drawing rounded corners for the layer’s background. | 0 |
- View
Using View programmatically
Connect the UI to Code
@IBOutlet weak var view: View!
Using View in Storyboard
The steps for use
- Drag a UIView into Storyboard.
- Set class to
View
- Set up attributes inspection.
- Border
Parameter | Type | Description | Default |
---|---|---|---|
borderColor | UIColor | The color of the layer’s border. | UIColor.clear |
borderWidth | CGFloat | The width of the layer’s border. | 0 |
- Corner Radius
Parameter | Type | Description | Default |
---|---|---|---|
cornerRadius | CGFloat | The radius to use when drawing rounded corners for the layer’s background. | 0 |
- Shadow
Parameter | Type | Description | Default |
---|---|---|---|
shadowColor | UIColor | The color of the layer’s shadow. | UIColor.clear |
shadowOpacity | Float | The opacity of the layer’s shadow. | 0 |
shadowOffset | CGSize | The offset (in points) of the layer’s shadow. | CGSize.zero |
shadowRadius | CGFloat | The blur radius (in points) used to render the layer’s shadow. | 0 |
- Gradient Background
Parameter | Type | Description | Default |
---|---|---|---|
gradientEnabled | Bool | Enable gradient background. | false |
gradientStartColor | UIColor | Start color gradient background. | UIColor.clear |
gradientEndColor | UIColor | End color gradient background. | UIColor.clear |
gradientHorizontal | Bool | Is the horizontal gradient background. | false |
- TableView
Using TableView programmatically
Connect the UI to Code
@IBOutlet weak var dataTableView: TableView!
- Image Size
Custom Size Image
dataTableView.imageSizePercentage = .percentage75
Parameter | Type | Description | Default |
---|---|---|---|
imageSizePercentage | Percentage | The image size, in percentage of the TableView size. | percentage75 |
- Color & Font
Custom Color & Font
dataTableView.titleColor = UIColor.black
dataTableView.titleFont = UIFont(name: "HelveticaNeue-Bold", size: 18)
dataTableView.messageColor = UIColor.lightGray
dataTableView.messageFont = UIFont(name: "HelveticaNeue-Regular", size: 17)
Parameter | Type | Description | Default |
---|---|---|---|
titleColor | UIColor | The color of title. | UIColor.black |
titleFont | UIFont | The font of title. | UIFont(name: "HelveticaNeue-Bold", size: 18) |
messageColor | UIColor | The color of message. | UIColor.lightGray |
messageFont | UIFont | The font of message. | UIFont(name: "HelveticaNeue-Regular", size: 17) |
- Empty View
Example of use in numberOfRowsInSection
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if names.count == 0 {
dataTableView.setEmptyView(title: "Oops!", message: "Data not found.", messageImage: #imageLiteral(resourceName: "data_not_found_icon"), animated: true)
} else {
dataTableView.restore()
}
return names.count
}
- Function
setEmptyView
for show image only.
Example of use
dataTableView.setEmptyView(messageImage: #imageLiteral(resourceName: "no_data_icon"), animated: true)
Output
- Function
setEmptyView
for show title only.
Example of use
dataTableView.setEmptyView(title: "Data not found.")
Output
- Function
setEmptyView
for show title and message.
Example of use
dataTableView.setEmptyView(title: "Oops!", message: "Data not found.")
Output
- Function
setEmptyView
for show image and title and message.
Example of use
dataTableView.setEmptyView(title: "Oops!", message: "Data not found.", messageImage: #imageLiteral(resourceName: "data_not_found_icon"), animated: true)
Output
- Restore
The restore TableView
Example of use
dataTableView.restore()
Using TableView in Storyboard
The steps for use
- Drag a UITableView into Storyboard.
- Set class to
TableView
- Set up attributes inspection.
- Border
Parameter | Type | Description | Default |
---|---|---|---|
borderColor | UIColor | The color of the layer’s border. | UIColor.clear |
borderWidth | CGFloat | The width of the layer’s border. | 0 |
- CollectionView
Using CollectionView programmatically
Connect the UI to Code
@IBOutlet weak var dataCollectionView: CollectionView!
- Image Size
Custom Size Image
dataCollectionView.imageSizePercentage = .percentage75
Parameter | Type | Description | Default |
---|---|---|---|
imageSizePercentage | Percentage | The image size, in percentage of the CollectionView size. | percentage75 |
- Color & Font
Custom Color & Font
dataCollectionView.titleColor = UIColor.black
dataCollectionView.titleFont = UIFont(name: "HelveticaNeue-Bold", size: 18)
dataCollectionView.messageColor = UIColor.lightGray
dataCollectionView.messageFont = UIFont(name: "HelveticaNeue-Regular", size: 17)
Parameter | Type | Description | Default |
---|---|---|---|
titleColor | UIColor | The color of title. | UIColor.black |
titleFont | UIFont | The font of title. | UIFont(name: "HelveticaNeue-Bold", size: 18) |
messageColor | UIColor | The color of message. | UIColor.lightGray |
messageFont | UIFont | The font of message. | UIFont(name: "HelveticaNeue-Regular", size: 17) |
- Empty View
Example of use in numberOfItemsInSection
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if names.count == 0 {
dataCollectionView.setEmptyView(title: "Oops!", message: "Data not found.", messageImage: #imageLiteral(resourceName: "data_not_found_icon"), animated: true)
} else {
dataCollectionView.restore()
}
return names.count
}
- Function
setEmptyView
for show image only.
Example of use
dataCollectionView.setEmptyView(messageImage: #imageLiteral(resourceName: "no_data_icon"), animated: true)
Output
- Function
setEmptyView
for show title only.
Example of use
dataCollectionView.setEmptyView(title: "Data not found.")
Output
- Function
setEmptyView
for show title and message.
Example of use
dataCollectionView.setEmptyView(title: "Oops!", message: "Data not found.")
Output
- Function
setEmptyView
for show image and title and message.
Example of use
dataCollectionView.setEmptyView(title: "Oops!", message: "Data not found.", messageImage: #imageLiteral(resourceName: "data_not_found_icon"), animated: true)
Output
- Restore
The restore CollectionView
Example of use
dataCollectionView.restore()
Using CollectionView in Storyboard
The steps for use
- Drag a UICollectionView into Storyboard.
- Set class to
CollectionView
- Set up attributes inspection.
- Border
Parameter | Type | Description | Default |
---|---|---|---|
borderColor | UIColor | The color of the layer’s border. | UIColor.clear |
borderWidth | CGFloat | The width of the layer’s border. | 0 |
Example
To run the example project, clone the repo, and run pod install
from the Example directory first.
Author
nattaponph, [email protected]
License
ADVHelper is available under the MIT license. See the LICENSE file for more info.