This file contains 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
enum Gender: Int { | |
case Male | |
case Female | |
/* Trick to get the count of enum */ | |
static let count: Int = { | |
var max: Int = 0 | |
while let _ = Gender(rawValue: max) { max += 1 } | |
return max | |
}() |
This file contains 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
enum DetailInfoRowType: Int { | |
case AddressRow | |
case PhoneRow | |
case OpeningHoursRow | |
case DiscountHoursRow | |
case PriceRangesRow | |
case IntroRow | |
} | |
let detailInfoRow = detailInfoRows[indexPath.row] |
This file contains 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
/* We call layoutIfNeeded() immediately after reloadData() | |
* to force collection view to perform layout immediately | |
* This is required to let the setContentOffset() in dispatch block to be executed | |
* after collection view has completed performing its layout to scroll to the correct offset | |
* For further explanations, please see: http://goo.gl/BpzlA5 and http://goo.gl/6CH64b | |
*/ | |
self.collectionView.reloadData() | |
self.collectionView.layoutIfNeeded() | |
dispatch_async(dispatch_get_main_queue(), { |
This file contains 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
/* We call layoutIfNeeded() immediately after reloadData() | |
* to force table view to perform layout immediately | |
* This is required to let the setContentOffset() in dispatch block to be executed | |
* after table view has completed performing its layout to scroll to the correct offset | |
* For further explanations, please see: http://goo.gl/BpzlA5 and http://goo.gl/6CH64b | |
*/ | |
self.tableView.reloadData() | |
self.tableView.layoutIfNeeded() | |
dispatch_async(dispatch_get_main_queue(), { |
This file contains 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 textViewDidBeginEditing(textView: UITextView) { | |
/* Simulate the placeholder effect */ | |
if textView.text == <Simulated placeholder> { | |
textView.text = "" | |
textView.textColor = UIColor.blackColor() | |
} | |
} | |
func textViewDidEndEditing(textView: UITextView) { | |
/* Simulate the placeholder effect */ |
This file contains 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
textField.addTarget(self, action: #selector(textFieldEditingChanged(_:)), | |
forControlEvents: .EditingChanged) |
This file contains 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
/* Dismiss keyboard */ | |
UIApplication.sharedApplication().sendAction(#selector(resignFirstResponder), to: nil, from: nil, forEvent: nil) |
This file contains 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
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.tableView.tableFooterView = UIView() | |
} |
This file contains 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
/* Get the height of ONE line text with given width and font */ | |
func heightOfOneLineString(text: String, width: CGFloat, font: UIFont) -> CGFloat { | |
let rectOneLine = NSString(string: text).boundingRect(with: CGSize(width: width, height: CGFloat(MAXFLOAT)), | |
options: .truncatesLastVisibleLine, | |
attributes: [ NSFontAttributeName: font ], | |
context: nil) | |
return rectOneLine.size.height | |
} | |
/* Get the height of MULTIPLE lines text with given width and font */ |
This file contains 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 textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { | |
/* Allow integer only */ | |
let invalidCharacters = CharacterSet.decimalDigits.inverted | |
return string.rangeOfCharacter(from: invalidCharacters) == nil | |
} |
OlderNewer