YZClasses
Features
- YZAppConfig class used to configure
designWidth, designHeight, navigationBarHeight
. - YZCALayer is type of CALayer extension to add or apply
applyShadow, addCornerRadius, addBorder, addGradient
. - YZUIView is type of UIView extension to add or apply
addCornerRadius, applyShadow, addGradient, addConstraint, addBorder
Requirements
- iOS 12.0+
- Xcode 11+
- Swift 5.0+
Usage
1. YZAppConfig Class
YZAppConfig
is used to set your design width, height, navigationBarHeight
provided by your designer. By configure design settings, it will calculate widthRatio, heightRatio, safeAreaInsets
Initialisation:
YZAppConfig.initialise(375, designHeight: 667, navigationBarHeight: 88)
Properties:
YZAppConfig.appDelegate
- ProvidesUIApplicationDeletage
object usingUIApplication.shared.delegate!
.YZAppConfig.navigationBarHeight
- Provides setted navigation bar height.YZAppConfig.designWidth
- Provides setted design width.YZAppConfig.designHeight
- Provides setted design height.YZAppConfig.width
- Provides currently running iOS Device/Simulator width usingUIScreen.main.bounds.size.width
.YZAppConfig.height
- Provides currently running iOS Device/Simulator height usingUIScreen.main.bounds.size.height
.YZAppConfig.widthRatio
- Provides width ratio by calculatingwidth/designWidth
.YZAppConfig.heightRatio
- Provides height ratio by calculatingheight/designHeight
.YZAppConfig.safeAreaInsets
- ProvidesUIEdgeInsets
object usingappDelegate.window!!.safeAreaInsets
.YZAppConfig.safeAreaInsets
- ProvidesUIEdgeInsets
object usingappDelegate.window!!.safeAreaInsets
.
2. YZCALayer
YZCALayer
is extension of CALayer
to addCornerRadius
, applyShadow
, addGradient
, addConstraintWithSuperView
, addBorder
, addDashBorder
.
Functions:
public func addCornerRadiusBy(_ roundingCorners: UIRectCorner = [.allCorners], cornerRadii: CGSize = .zero, fillColor: UIColor? = .black)
- It will use to add cornder radius usingCAShapeLayer
, with specific parameters.public func applyShadowWith(_ roundingCorners: UIRectCorner = [.allCorners], cornerRadii: CGSize = .zero, fillColor: UIColor? = nil, shadowOffset: CGSize = .zero, shadowColor: UIColor, shadowRadius: CGFloat = 3, shadowOpacity:Float = 0)
- It will use to draw a shadow usingCAShapeLayer
, with specific parameters.public func addBorderBy(_ roundingCorners: UIRectCorner = [.allCorners], cornerRadii: CGSize = .zero, fillColor: UIColor? = .black, strokeColor: UIColor? = nil, lineWidth: CGFloat = 1)
- It will use to draw a border usingCAShapeLayer
, with specific parameters.public func addDashBorderBy(_ cornerRadius: CGFloat = .leastNonzeroMagnitude, fillColor: UIColor? = .black, dashColor: UIColor? = nil, dashHeight: CGFloat = 1, dashWidth: CGFloat = 5, spaceBetweenDash: CGFloat = 5)
- It will use to draw a dash border usingCAShapeLayer
, with specific parameters.public func addGradient(_ colors: [UIColor], gradientPoint: YZGradientPoint, roundingCorners: UIRectCorner = [.allCorners], cornerRadii: CGSize = .zero)
- It will use to add gradient colors usingCAGradientLayer
, with specific parameters.
3. YZUIView
YZUIView
is extension of UIView
to addCornerRadius
, applyShadow
, addGradient
, addConstraintWithSuperView
, addBorder
, addDashBorder
. It will internally call YZCALayer
functions to design UIView
as per needed.
Properties:
isRound
-@IBInspectable isRound
property is used to draw fully round on selectedUIView
.borderWidth
-@IBInspectable borderWidth
property is used to draw border around on selectedUIView
.borderColor
-@IBInspectable borderColor
property is used to apply border color on selectedUIView
.cornerRadius
-@IBInspectable cornerRadius
property is used to apply corner radius on selectedUIView
.shadowRadius
-@IBInspectable shadowRadius
property is used to define shadow radius on selectedUIView
.shadowOpacity
-@IBInspectable shadowOpacity
property is used to define shadow opacity on selectedUIView
.shadowColor
-@IBInspectable shadowColor
property is used to define shadow color on selectedUIView
.shadowOffset
-@IBInspectable shadowOffset
property is used to define shadow offsets on selectedUIView
.zPosition
-@IBInspectable zPosition
property is used to definezPosition
.
Functions:
public func addCornerRadiusBy(_ roundingCorners: UIRectCorner = [.allCorners], cornerRadii: CGSize = .zero, fillColor: UIColor? = .black)
- It will use to add cornder radius aroundUIView
, with specific parameters.public func applyShadowWith(_ roundingCorners: UIRectCorner = [.allCorners], cornerRadii: CGSize = .zero, fillColor: UIColor? = nil, shadowOffset: CGSize = .zero, shadowColor: UIColor, shadowRadius: CGFloat = 3, shadowOpacity:Float = 0)
- It will use to draw a shadow aroundUIView
, with specific parameters.public func addConstraintWithSuperView(_ topConstraint: CGFloat, leadingConstraint: CGFloat, bottomConstraint: CGFloat, trailingConstraint: CGFloat)
- It will use to add constraint with superView.public func addDashBorderBy(_ cornerRadius: CGFloat = .leastNonzeroMagnitude, fillColor: UIColor? = .black, dashColor: UIColor? = nil, dashHeight: CGFloat = 1, dashWidth: CGFloat = 5, spaceBetweenDash: CGFloat = 5)
- It will use to draw a dash border usingCAShapeLayer
, with specific parameters.public func addBorderBy(_ roundingCorners: UIRectCorner = [.allCorners], cornerRadii: CGSize = .zero, fillColor: UIColor? = .black, strokeColor: UIColor? = nil, lineWidth: CGFloat = 1)
- It will use to draw a border aroundUIView
, with specific parameters.public func addDashBorderBy(_ cornerRadius: CGFloat = .leastNonzeroMagnitude, fillColor: UIColor? = .black, dashColor: UIColor? = nil, dashHeight: CGFloat = 1, dashWidth: CGFloat = 5, spaceBetweenDash: CGFloat = 5)
- It will use to draw a dash border aroundUIView
, with specific parameters.public func addGradient(_ colors: [UIColor], gradientPoint: YZGradientPoint, roundingCorners: UIRectCorner = [.allCorners], cornerRadii: CGSize = .zero)
- It will use to add gradient colors insideUIView
, with specific parameters.
4. YZArray
YZArray
is extension of Array
collection data type to perform operation like uniqueElements
or removeElements
.
Properties:
uniqueElements
- It will provide unique elements array.
Functions:
public mutating func uniqueElementsInPlace()
- It will use to make unique elements array type without generating another copy of array type.public mutating func remove(_ elements: [Element])
- It will use to remove one or more than one provided elements from existing array.
5. YZURL
YZURL
is extension of URL
and provides following properties and functions.
Properties:
isFileExists
- It will check file existance for given URL.convertToData
- It will generate data object from given file URL.
Functions:
public func deleteFile()
- It will check file existance and delete from given URL.public func getThumbnailFromVideo()
- It will use to get thumbnail image from given video file URL.public func compressVideo(_ outputURL: URL, handler:@escaping (_ exportSession: AVAssetExportSession?, _ compressVideoURL: URL?)-> Void)
- It will use to compress video for given URL.public func getValueForQuery(_ parameter: String)
- It will use to get value from given query parameter.
6. YZDictionary
YZDictionary
is extension of Dictionary
and NSDictionary
which provides following properties and functions.
Properties:
toJSON
- It will used to convertDictionary
to JSON String.convertToData
- It will generate data object from given file URL.
Functions:
public mutating func merge(_ other: Dictionary)
- It will merge existing dictionary with provided dictionary.public func getDoubleValue(forKey: String)
- It will provideDouble
type value from givenNSDictionary
.public func getFloatValue(forKey: String)
- It will provideFloat
type value from givenNSDictionary
.public func getUIntValue(forKey: String)
- It will provideUInt
type value from givenNSDictionary
.public func getIntValue(forKey: String)
- It will provideInt
type value from givenNSDictionary
.public func getInt64Value(forKey: String)
- It will provideInt64
type value from givenNSDictionary
.public func getInt32Value(forKey: String)
- It will provideInt32
type value from givenNSDictionary
.public func getInt16Value(forKey: String)
- It will provideInt16
type value from givenNSDictionary
.public func getInt8Value(forKey: String)
- It will provideInt8
type value from givenNSDictionary
.public func getStringValue(forKey: String)
- It will provideString
type value from givenNSDictionary
.public func getBooleanValue(forKey: String)
- It will provideBool
type value from givenNSDictionary
.
7. YZString
YZString
file used to perform some string related manipulation using exention of String
, NSMutableAttributedString
and NSAttributedString
to perform manipulation and provides following properties and functions.
Properties:
isEmailAddressValid
- It is used to check email address valid or not, it will returnBool
value.trimmedString
- It is used to trimm characters like white space and new lines, it will returnString
value.isOnlyNumericValue
- It is used to check given string has numeric value or not, it will returnBool
value.toDouble
- It is used to convertString
type value toDouble
type value.toFloat
- It is used to convertString
type value totoFloat
type value.toInt
- It is used to convertString
type value totoInt
type value.toInt64
- It is used to convertString
type value totoInt64
type value.toInt32
- It is used to convertString
type value totoInt32
type value.toInt16
- It is used to convertString
type value totoInt16
type value.toInt8
- It is used to convertString
type value totoInt8
type value.camelCaseLetter
- It is used to display string in camel case letter, it will returnString
type value.htmlToAttributedString
- It is used to convert HTML to Attributed String.htmlToString
-It is used to convert HTML to String.initialCharactersFromWord
- It is used to get characters from word to display as user avatar.isPhoneNumberValid
- It is used to check phoe number is valid or not. It will returnBool
value.adjustedNationalNumber
- Adjust national number for display by adding leading zero if needed. Used for basic formatting functions.
Functions:
public func contains(_ find: String)
- It is used to check given string is contain or not.public func isEqual(_ otherString: String)
- It is used to compare two string.public func singleLineHeightFor(_ font: UIFont)
- It is used to calculate single line height for given string based on provided font.public func heightForFixed(_ width: CGFloat, font: UIFont)
- It is used to calculate height for given string based on fixed width.public func widthForFixed(_ height: CGFloat, font: UIFont)
- It is used to calculate width for given string based on fixed height.public func capitalizingFirstLetter()
- It is used to capitalizing first letter of given string or word.public func strikeThroughLine(_ color: UIColor, textFont: UIFont, foregroundColor: UIColor)
- It is used to draw strike line on given string. It will call internallyNSMutableAttributedString
function.public func addVertical(_ lineSpacing: CGFloat, alignment: NSTextAlignment, lineBreakMode: NSLineBreakMode = .byTruncatingTail, textFont: UIFont, foregroundColor: UIColor)
- It is used to add verticle line space on given string as per given parameters. It will call internallyNSMutableAttributedString
function.public func addCharacters(_ spacing: CGFloat, alignment: NSTextAlignment = .natural, lineBreakMode: NSLineBreakMode = .byTruncatingTail, textFont: UIFont, foregroundColor: UIColor)
- It is used to add space between given characters as per given parameters. It will call internallyNSMutableAttributedString
function.public func setString(_ alignment: NSTextAlignment = .natural, textFont: UIFont? = nil, foregroundColor: UIColor? = nil)
- It is used to set string alignment, font, foreground color as per given parameter. It will call internallyNSMutableAttributedString
function.public func addCharacters(_ shadowColor: UIColor, shadowBlurRadius: CGFloat, shadowOffset: CGSize = .zero, textFont: UIFont, foregroundColor: UIColor)
- It will use to apply drop shadow effects to characters
8. YZButtons
YZButtons
file contain multiple UIButton
classes and exenstion of UIButton
which provides following classes and functions.
Classes:
YZParentWidthBTN
- It is used when, you want to designUIButton
as per multiple device support and applywidthRatio
.YZParentHeightBTN
- It is used when, you want to designUIButton
as per multiple device support and applyheightRatio
.
Functions:
public func setAttributed(_ texts: [String], attributes: [[NSAttributedString.Key : Any]], state: UIControl.State)
- It is used to set texts and it's attributes as per given parameters. It will internally callNSAttributedString
function.
9. YZLabels
YZLabels
file contain multiple UILabel
classes and exenstion of UILabel
which provides following classes, properties and functions.
Classes:
YZParentWidthLBL
- It is used when, you want to designUILabel
as per multiple device support and applywidthRatio
.YZParentHeightLBL
- It is used when, you want to designUILabel
as per multiple device support and applyheightRatio
.
Properties:
isTruncated
- It is used to check given label is truncated or not. It will returnBool
type value.
Functions:
public func addCharacters(_ spacing: CGFloat, alignment: NSTextAlignment = .natural, lineBreakMode: NSLineBreakMode = .byTruncatingTail, textFont: UIFont, foregroundColor: UIColor)
- It is used to add space between given characters as per given parameters. It will call internallyString
function.public func setAttributed(_ texts: [String], attributes: [[NSAttributedString.Key : AnyObject]])
- It is used to add texts and it's attributes.public func setVertical(_ lineSpacing: CGFloat, alignment: NSTextAlignment, lineBreakMode: NSLineBreakMode = .byTruncatingTail, textFont: UIFont, foregroundColor: UIColor)
- It is used to add verticle line space on given texts as per given parameters. It will call internallyString
function.public func addStrikeThroughLine(_ color: UIColor, textFont: UIFont, foregroundColor: UIColor)
- It is used to draw strike line on given texts. It will call internallyString
function.
10. YZTextViews
YZTextViews
file contain multiple UITextView
classes and extension of UITextView
which provides following classes, properties, protocols and functions.
Classes:
YZParentWidthTV
- It is used when, you want to designUITextView
as per multiple device support and applywidthRatio
.YZParentHeightTV
- It is used when, you want to designUITextView
as per multiple device support and applyheightRatio
.YZWithoutInsetTV
- It is used when, you want to designUITextView
without any additional insets or padding.YZLinkableTV
- It is used when, you want to get value forUIDataDetectorTypes
.
Protocols:
YZLinkableTVDelegate
- It is used when, you want to get value forUIDataDetectorTypes
.
Functions:
public func newHeightUsing(_ baseHeight: CGFloat)
- Calculates if new textview height (based on content) is larger than a base height.
11. YZTextFields
YZTextFields
file contain multiple UITextField
classes and extension of UITextField
which provides following classes and functions.
Classes:
YZParentWidthTF
- It is used when, you want to designUITextField
as per multiple device support and applywidthRatio
.YZParentHeightTF
- It is used when, you want to designUITextField
as per multiple device support and applyheightRatio
.YZParentPaddingTF
- It is used to set padding for TextRect, PlaceHolderRect and EditingRect usingUIEdgeInsets
.
Functions:
public func addInputAccessory(_ text: String, textFont: UIFont, tintColor: UIColor? = nil, rect: CGRect = .zero)
- It is used to add input accessory view toUITextField
.public func fixCaretPosition()
- It is used to move the carent to the correct position by removing the trailing whitespace.public func setAttributed(_ placeHolder: String?, color: UIColor, font: UIFont)
- It is used to set attributed place holder with given parameteres.
12. YZColor
YZColor
file contain UIColor
extension which provides following functions.
Functions:
public convenience init(_ hexaValue: String, alpha: CGFloat = 1.0)
- It is used to initializeUIColor
object from given hexa decimal value and alpha value.public static func initWith(_ red: Int, green: Int, blue: Int, alpha: CGFloat)
- It is used to initializeUIColor
object from given RGBA value.public func brightenedBy(_ factor: CGFloat)
- It is used to add bright color effect on exisiting color.
13. YZImage
YZImage
file contain UIImage
extension which provides following properties and functions.
Properties:
fixedOrientation
- It is used to fixed orientation of given image.
Functions:
public static func generateQRCodeFrom(_ string: String)
- It is used to generate QRCode image from given stringpublic static func getSquareImage()
- It is used to generate square image.public func resizeImageWith(_ width: CGFloat, height: CGFloat)
- It is used to resize image with given parameters.public func scaleTo(_ newSize: CGSize, isAspectFill: Bool = true)
- It is used to scales an image to fit within a bounds with a size governed by the passed size. Also keeps the aspect ratio.public func scaleAndManageAspectRatio(_ width: CGFloat)
- It is used to reduce image resolution and maintain aspect ratio.
14. YZIndexPath
YZIndexPath
file contain IndexPath
extension which provides functions.
Functions:
public static func indexPathForCellContaining(_ view: UIView, tableView: UITableView)
- It is used to getIndexPath
fromUITableView
.public static func indexPathForCellContaining(_ view: UIView, collectionView: UICollectionView)
- It is used to getIndexPath
fromUICollectionView
.
15. YZViewController
YZViewController
file contain multiple extension of UIWindow
, UIViewController
, and UIApplication
which provides following properties and functions.
Properties:
currentVisibleViewController
- It is used to get current visibleUIViewController
forUIWindow
,UIViewController
, andUIApplication
.
Functions:
public static func getCurrentVisibleVCFor(_ vc: UIViewController)
- It is used to get current visibleUIViewController
for givenUIViewController
.
16. YZActivityIndicator
YZActivityIndicator
class used to initialize custom indicator view using image, which have following properties and functions.
Properties:
isAnimating
- It will provideBool
value to check isAnimating or not.hidesWhenStopped
- It will used to set property to hide indicator view when it is stopped animation.
Functions:
public func startAnimating()
- It is used to start animation.public func stopAnimating()
- It is used to stop animation.
17. YZConstrainedViews
YZConstrainedViews
file contains multiple classes used to set as parent class for application, which provide following classes.
Protocol:
YZUserTapDelegate
- It is used to get user tap event on text for tableCell, collectionCell, and headerFooter views.YZTextFieldDelegate
- It is used to getUITextField
events.
Classes:
YZParentControl
- It is a sub-class ofUIControl
use to set as parent class.YZParentCVC
- It is a sub-class ofUICollectionViewCell
use to set as parent class.YZParentCRV
- It is a sub-class ofUICollectionReusableView
use to set as parent class.YZParentHFV
- It is a sub-class ofUITableViewHeaderFooterView
use to set as parent class.YZParentTVC
- It is a sub-class ofUITableViewCell
use to set as parent class.YZParentView
- It is a sub-class ofUIView
use to set as parent class.
17. YZLinkLabel
YZLinkLabel
class used to detect mention, hash tags or URLs from given string which provide following properties and functions.
Properties:
arrOfHashTags
- It is used to get number of count for hash tags.arrOfMentions
- It is used to get number of count for mentions tags.arrOfURLs
- It is used to get number of count for URLs.delegate
- It is used to set delegate to get events.
Functions:
public func set(_ attributedString: NSAttributedString, linebreak : NSLineBreakMode = .byTruncatingTail)
- It is used to set attributed texts.
18. YZPermission
YZPermission
class is used to check permissions like camera access, photo library access etc... which have following functions.
Functions:
public func cameraAccess(permissionWithStatus block: @escaping PermissionStatus)
- It is used to check camera access permission.public func photoLibraryAccess(permissionWithStatus block: @escaping PermissionStatus)
- It is used to check photo library access permission.public func locationAccess(permissionWithStatus block: @escaping PermissionStatus)
- It is used to check location access permission.
19. YZNumbers
YZNumbers
class is used to manipulate some number related operations, following properties and functions.
Properties:
suffixNumber
- It is used to convertDouble
value toString
in K(Thousands) and M(Million) forms.
Functions:
public mutating func roundTo(_ places: Int)
- It is used to rounds theDouble
value to decimal places value.
Installation
YZClasses is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'YZClasses', '~> 0.1.6'
Author
Vipul Patel (Yudiz Solutions Pvt. Ltd.), [email protected]
License
YZClasses is available under the MIT license. See the LICENSE file for more info.