首页 > 学院 > 开发设计 > 正文

swift 开发 - 常用函数

2019-11-09 15:17:11
字体:
来源:转载
供稿:网友

//计算文字高度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            }    }

    }

    

}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表