extension for String
extension String {
func stringByTrimmingLeadingAndTrailingWhitespace() -> String {
let leadingAndTrailingWhitespacePattern = "(?:^\\s+)|(?:\\s+$)"
if let regex = NSRegularExpression(pattern: leadingAndTrailingWhitespacePattern, options: .CaseInsensitive, error: nil) {
let range = NSMakeRange(0, countElements(self))
let trimmedString = regex.stringByReplacingMatchesInString(self, options: .ReportProgress, range:range, withTemplate:"$1")
return trimmedString
} else {
return self
}
}
}
extension for UIColor
extension UIColor {
class func trueColor() -> UIColor {
return UIColor(red: 0.1882, green:0.6784, blue:0.3882, alpha:1.0)
}
class func falseColor() -> UIColor {
return UIColor(red:0.7451, green:0.2275, blue:0.1922, alpha:1.0)
}
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者