title: How to create a hex color string UIColor initializer in Swift?
body: <p>I am using this code for create UIColor from hex value. Its working perfectly.</p>
  
  <pre><code>extension UIColor {
  convenience init(red: Int, green: Int, blue: Int) {
     assert(red &gt;= 0 &amp;&amp; red &lt;= 255, "Invalid red component")
     assert(green &gt;= 0 &amp;&amp; green &lt;= 255, "Invalid green component")
     assert(blue &gt;= 0 &amp;&amp; blue &lt;= 255, "Invalid blue component")
  
     self.init(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: 1.0)
  }
  
  convenience init(netHex:Int) {
     self.init(red:(netHex &gt;&gt; 16) &amp; 0xff, green:(netHex &gt;&gt; 8) &amp; 0xff, blue:netHex &amp; 0xff)
  }
  }
  </code></pre>
  
  <p>Usage:</p>
  
  <pre><code>var textColor = UIColor(netHex: 0xffffff)
  </code></pre>
  
  <p>This code works perfectly for Int hex code. But It needs hex code 0xffffff as Int type. I am having the hex code from web service. It will be like "#ffffff" (String not Int). I can convert this string like "0xffffff". But I can't convert from "0xffffff"(String) to 0xffffff (Int).</p>
  
  <p>I need something like this </p>
  
  <pre><code>var textColor = UIColor(netHex: "0xffffff")
  </code></pre>
  
  <p>or better like this:</p>
  
  <pre><code>var textColor = UIColor(netHex: "#ffffff")
  </code></pre>
  
  <p>Thanks in advance.</p>