thieumao

CommonUtility

Jan 4th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.52 KB | None | 0 0
  1. import UIKit
  2.  
  3. class CommonUtility {
  4.     class func getPortraitScreenSize() -> CGSize {
  5.         let w = UIScreen.main.bounds.size.width
  6.         let h = UIScreen.main.bounds.size.height
  7.         return CGSize(width: min(w, h), height: max(w, h))
  8.     }
  9.    
  10.     class func getLandscapeScreenSize() -> CGSize {
  11.         let w = UIScreen.main.bounds.size.width
  12.         let h = UIScreen.main.bounds.size.height
  13.         return CGSize(width: max(w, h), height: min(w, h))
  14.     }
  15.    
  16.     class func isValidEmail(email:String?) -> Bool {
  17.         let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}"
  18.         let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx)
  19.         return emailTest.evaluate(with: email)
  20.     }
  21.    
  22.     class func isValidPassword(password:String?) -> Bool {
  23.         if let pass = password, pass.characters.count >=  0 {
  24.             return true
  25.         }
  26.         return false
  27.     }
  28.    
  29.     class func isPortrait() -> Bool {
  30. //        return UIScreen.main.bounds.size.height == CommonUtility.getPortraitScreenSize().height
  31.         return UIDevice.current.orientation.isPortrait
  32.     }
  33.    
  34.     class func isIphone4or5() -> Bool {
  35.         return UIScreen.main.bounds.size.height <= 588.0
  36.     }
  37.    
  38.     class func subString(input: String, from: Int, to: Int) -> String {
  39.         let start = input.index(input.startIndex, offsetBy: from)
  40.         let end = input.index(input.startIndex, offsetBy: to)
  41.         let range = start..<end
  42.         return input.substring(with: range)
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment