Showing: 101 - 110 of 137 Articles

Get date before year

public func getDateBeforeYear(year : Int) -> Date{     let gregorian: NSCalendar = NSCalendar(calendarIdentifier: NSCalendar.Identifier.gregorian)!     let currentDate: Date = Date()     let components: NSDateComponents = NSDateComponents()          components.year = -year     return gregorian.date(byAdding: components as DateComponents, to: currentDate, options: NSCalendar.Options(rawValue: 0))! }

UILable Text Spacing

extension UILabel{     func setTextSpacing(spacing: CGFloat){         let attributedString = NSMutableAttributedString(string: text!)         if textAlignment == .center || textAlignment == .right {             attributedString.addAttribute(NSKernAttributeName, value: spacing, range: NSRange(location: 0, length: attributedString.length-1))         } else {             attributedString.addAttribute(NSKernAttributeName, value: spacing, range: NSRange(location: 0, length: attributedString.length))         …

Username Validation without space and max length

Call function from text field delegate method and get valid username. let USERNAMERANGE = “ABCDEFGHIJKLMONPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.” let KALERTVALIDUSERNAME = “Username can only use letters, numbers, underscore and periods.” public func setUsernameFormate(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String)-> Bool{     var strUserName = textField.text! as …

Strong Password Validation

public func isValidPassword(strPassword : String) -> Bool{     let charactersetspecialcharacter = CharacterSet(charactersIn: “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLKMNOPQRSTUVWXYZ0123456789”)          if strPassword.rangeOfCharacter(from: charactersetspecialcharacter.inverted) == nil {         return false     }          let capitalLetterRegEx  = “.*[A-Z]+.*”     let textcapitallattertest = NSPredicate(format:”SELF MATCHES %@”, capitalLetterRegEx)          …

Image Caching With AFNetworking causes memory warning in UICollectionView

We have use SDWebImage instead of AFNetworking to handle memory warning. You can find swift code from below link. here is below code: [imageView sd_setImageWithURL:[NSURL URLWithString:@”http://www.domain.com/path/to/image.jpg”] placeholderImage:[UIImage imageNamed:@”placeholder.png”]]; // Some time may possible that this cause memory warning than use below code to overcome(This causes …

UIView Extension with support CornerRadius, borderWidth, borderColor, roundCorners, shadowColor, shadowOpacity, shadowOffset, shadowRadius.

While we want to set uiview property (like CornerRadius, borderWidth, borderColor, roundCorners, shadowColor, shadowOpacity, shadowOffset, shadowRadius) at that time we use code or user defined runtime attribute for that but using this extension we can esily update property from attribute inspector. code support SWIFT 3.0 …