title: uibutton text on background image using swift
body: <p>I am new to IOS swift and i have been trying to solve this problem for the past few days. I am trying to create a UIButton with a background image downloaded from server and add a text on the button itself on top of the background image.</p>
  
  <pre><code>for button in data {
              let btn = UIButton.buttonWithType(UIButtonType.Custom) as UIButton
              btn.frame = CGRectMake(x, y, 125, 125)
              btn.backgroundColor = UIColor.greenColor()
              btn.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
              btn.setTitle(button["button_text"] as NSString, forState:UIControlState.Normal)
              btn.addTarget(self, action: "buttonTapped:", forControlEvents: UIControlEvents.TouchUpInside)
              btn.titleLabel?.font = UIFont(name: "Arial", size: 15)
              btn.titleLabel?.textAlignment = .Center
              btn.titleLabel?.numberOfLines = 5
              btn.layer.borderColor = UIColor.grayColor().CGColor
              btn.layer.borderWidth = 1
  
              var item_image_url:NSString = button["button_image"] as NSString
              var imgURL: NSURL = NSURL(string: item_image_url)!
              let request: NSURLRequest = NSURLRequest(URL: imgURL)
              NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler: {(response: NSURLResponse!,data: NSData!,error: NSError!) -&gt; Void in
                  var image = UIImage(data: data)
                  btn.setImage(image, forState: UIControlState.Normal)
              })
  
              self.view.addSubview(btn)
          }
  </code></pre>
  
  <p>Please help! Thanks in advance..</p>
  
  <p>KL</p>