mercredi 5 août 2015

how to set button background image size


I want to create this button in my application. I have added a button to my view in storyboard. Set it's width and height constraints to 60px.

Then in code I've added corner radius and UIImage to background but the image filled the whole button background. The image is 22x22px. I want it to be centered in button like on my screenshot.

var pencilImage = UIImage(named: "pencil")!
pencilBtn.setBackgroundImage(pencilImage, forState: UIControlState.Normal)
pencilBtn.layer.cornerRadius = pencilBtn.frame.size.height / 2
pencilBtn.clipsToBounds = true

What should I code to solve this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire