美文网首页
Useful extensions

Useful extensions

作者: hoody | 来源:发表于2015-02-01 12:41 被阅读3次

    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)
        }
    }
    

    相关文章

      网友评论

          本文标题:Useful extensions

          本文链接:https://www.haomeiwen.com/subject/ponlxttx.html