//计算文字高度func heightSizeWithContent(content:String,widthSize:CGFloat,fontSize:Int) -> CGSize{ let contentSize = content.boundingRect(with: CGSize(width:widthSize, height:CGFloat(MAXFLOAT)), options:.usesLineFragmentOrigin, attributes: [NSFontAttributeName:UIFont.systemFont(ofSize: CGFloat(fontSize))], context: nil).size return contentSize}//剥出文字中的数字func extractTheNumberInTheText(str:String) -> Int{ var number = 0 let scanner = Scanner.init(string: str) scanner.scanUpToCharacters(from: CharacterSet.decimalDigits, into: nil) scanner.scanInt(&number) return number}//正则判断手机号func checkTelNumber(telNumber:String) -> Bool{ let pattern = "^1+[3578]+//d{9}" let PRed = NSPredicate.init(format: "SELF MATCHES %@", pattern) let isMatch = pred.evaluate(with: telNumber) return isMatch}//判断时间差以及是否是同一天func timeToDetermine(nowDate:Date,beforeDate:Date) -> Bool{ //开始比较 if Calendar.current.isDate(nowDate, inSameDayAs: beforeDate) { //它们是同一天 //获取两个时间差 let diffComponents = Calendar.current.dateComponents([Calendar.Component.hour], from: beforeDate, to: nowDate) if diffComponents.hour! >= 5 { return true } return false }else { //它们不是同一天 return true } }}
}
新闻热点
疑难解答