UITableView
let cell = tableView.dequeueReusableCell(withIdentifier: "cell1")
return cell!
(cell!.contentView .viewWithTag(11) as!UILabel).text = "aaaa"
(cell?.viewWithTag(11) as!UILabel).text = "aaaa"
String
let contentHeight = 50
let rowHeight = contentHeight + ("aaaa".isPhone() ? 40 : 20)
print("rowHeight为\(rowHeight)")
分类
import Foundation
import UIKit
extension NSString{
/*电话*/
func isPhone() ->Bool{
let MOBILE = "^1(3[0-9]|4[57]|5[0-35-9]|8[0-9]|7[06-8])\\d{8}$"
return NSPredicate(format:"self matches %@",MOBILE).evaluate(with:self)
}
/*邮箱*/
func isMail() ->Bool{
let mailReg = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$"
return NSPredicate (format:"self matches %@",mailReg).evaluate(with:self)
}
/*邮箱或者电话中的一个*/
func isOneOfPhoneAndMail()->Bool{
if self.range(of:"@").location != NSNotFound {
return self.isMail()
}else{
return self.isPhone()
}
}
}
网友评论