Requirements • Usage • Installation • Author • Liscence
To run the example project, clone the repo, and run pod install
from the Example directory first.
Swift-Utils requires iOS 10+ and is compatible with Swift 4.2 projects.
Swift Utils can be used to simplify various tasks. They are actually an extension to your UIView, UIViewController, NSObject etc.
view.shadowWithRoundCorner(cornerRadius: 10)
view.roundCorners([UIRectCorner.bottomLeft, UIRectCorner.topLeft], radius: 10)
view.dashedBorder(borderColor: .black, lineDashPattern: [2,2])
You can alter the animation directiona and position of the pop up.
// If you pass nil in controller, pop up will be added to UIWindow, else into the controller
view.addIn(nil, addFrom: .top, position: .center)
let parentController = view.parentContainerViewController()
self.view.topControllerInHierarchy()
myView.addBlurView(style: UIBlurEffect.Style.light)
view.lock()
button.lock()
view.unlock()
button.unlock()
You can customize the loader either using the Appearance class or by passing the parameters in the lock() function. For Example to cahnge the loader stle using Appearance class, simple add these lines in AppDelegate:
ASLoader.appearance().tintColor = .red
ASLoader.appearance().textColor = .white
ASLoader.appearance().font = UIFont.systemFont(ofSize: 12.0)
ASLoader.appearance().size = CGSize(width: 40, height: 40)
Customize loader by passing parameters. You are not required to pass all paramters. Just pass the ones, that you need to customize.
self.view.lock(text: "loading",
tintColor: .red, textColor: .white,
font: UIFont.systemFont(ofSize: 16),
centerImage: UIImage(named: "logo"),
size: CGSize(width: 30, height: 30))
self.showToast(message: "Success")
ASToast.appearance().toastBackgroundColor = .black
ASToast.appearance().textColor = .white
self.showToast(message: "Success",
backgroundColor: .black, textColor: .white,
font: UIFont.systemFont(ofSize: 16))
Simply add a view in storyboard and assign it the class "ASCustomizableView". This is best when you want round corners with shadow. You can then alter cretain properties from the attribute inspector such as:
showShadow // If true shadow will be drawn. If false, you can changes attributes like corner radius, border width and color etc.
borderColor
borderWidth
shadowRadius
shadowOpacity
cornerRadius
shadowColor
shadowOffset
These extensions can help you validate strings for a valid email, valid text, valid phoneNumber etc.
let myString = "[email protected]"
if myString.isBlank {
print("success")
}
if myString.isEmail {
print("success")
}
if myString.isAlphanumeric {
print("success")
}
if myString.isValidPassword {
print("success")
}
if myString.isPhoneNumber {
print("success")
}
let colorFromString = UIColor.hexColor("FF0000")
let colorFromInt = UIColor(rgb: 0xFF0000)
Date extensions are be used for comparing dates, getting stringFormats from date or getting timeStamps etc:
let date1 = Date()
let date2 = Date()
if date1.isGreaterThanDate(date: date2) {
}
if date1.isLessThanDate(date: date2) {
}
if date1.isEqualToDate(date: date2) {
}
let stringDate = date1.toDateString()
let stringDate2 = date1.toDateString(format: "yyyy-MM-dd", timezone: TimeZone(identifier: "UTC"))
// This method will return the time span between the date1 and current time. This is an ease for
//showing timestamp in applications like social timeline or chatting applications.
let time = date1.timeAgoValue() // returns "1 min Ago"
let tableView = UITableView()
// Add no Data text for empty table
tableView.handleEmptyTable(text: "No Data")
// Remove no Data text
tableView.handleEmptyTable(text: nil)
// Get index of an view inside a UITableViewCell
let indexPath = tableView.indexPath(for: sender) // Sender can be anything. UIView/UIButton/UILabel etc
Get tableView from the UITableViewCell. This is useful when you want to get the reference of UITableview inside the UITableViewCell class.
let tableView = cell.tableView
/// This hides the backButton title for the next controller
self.hideBackButtonTitle()
// This removes the back button from the navigation bar
self.removeBackButton()
/// You can set a custom back button using this extension
self.setCustomBackButton(image: UIImage(named: "back"))
// Show an alert from a controller
self.showAlert(title: "Alert", message: "Success", style: .alert)
textField.setPlaceholder(text: question.placeholder, color: .gray)
Swift-Utils is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'Swift-Utils'
amrit42087, [email protected]
Swift-Utils is available under the MIT license. See the LICENSE file for more info.