This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIImage { | |
/// Returns a image that fills in newSize | |
func resizedImage(newSize: CGSize) -> UIImage { | |
// Guard newSize is different | |
guard self.size != newSize else { return self } | |
UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0); | |
self.draw(in: CGRect(x:0, y:0, width:newSize.width, height:newSize.height)) | |
let newImage: UIImage = UIGraphicsGetImageFromCurrentImageContext()! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface NSDate (Formatted) | |
- (NSString*)dateStringByFormatted:(NSString*)formate; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func showAlert(title: String, message: String){ | |
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) | |
let ok = UIAlertAction(title: "Ok", style: .default) { (action) in | |
} | |
alert.addAction(ok) | |
present(alert, animated: true, completion: nil) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UILabel{ | |
func dynamicHeight() -> CGFloat { | |
let label = UILabel(frame: self.bounds) | |
label.numberOfLines = self.numberOfLines | |
label.lineBreakMode = self.lineBreakMode | |
label.font = self.font | |
label.text = self.text | |
label.sizeToFit() | |
return label.frame.size.height | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//create object | |
let alertController = UIAlertController(title: "Login ✉︎", message: "Please enter your username/email and password.", preferredStyle: .alert) | |
// create action object | |
// which can be used to handle the different action when user tapped on any one of them | |
let okAction = UIAlertAction(title: "Ok", style: .default) { (action) in | |
//handle ok button action | |
print("ok button tapped") | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func performLogin(alertController: UIAlertController) { | |
guard let textFields = alertController.textFields else { return } | |
var params = [String:String]() | |
for textField in textFields{ | |
if textField.placeholder == "Enter username"{ | |
params["username"] = textField.text | |
} | |
if textField.placeholder == "Enter password"{ | |
params["password"] = textField.text | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//create object | |
let alertController = UIAlertController(title: "Share ♂", message: "Share the your content on social media.", preferredStyle: .actionSheet) | |
// create action objects | |
// which can be useed to handle the different action when user tapped on any one of them | |
let facebookAction = UIAlertAction(title: "Facebook", style: .default) { (action) in | |
//handle facebook button action | |
print("facebook button tapped") | |
self.performLogin(alertController: alertController) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"city": "AGAWAM", | |
"loc": [ | |
-72.622739, | |
42.070206 | |
], | |
"pop": 15338, | |
"state": "MA", | |
"_id": "01001" |
OlderNewer