Reputation: 258
Can anyone help me scale a UIButton without scaling UIButton's imageView?
This code scale button and button's imageView. I want the button to be scaled without scaling the imageView.
button.transform = CGAffineTransform(scaleX: 3, y: 3)
button.backgroundColor = UIColor(red: 0, green: 126/255, blue: 229/255, alpha: 1)
button.layer.cornerRadius = $0.bounds.size.width / 2
Upvotes: 0
Views: 368
Reputation: 4570
Try this code, And set content insets from storyboard.
button.backgroundColor = UIColor(red: 0, green: 126/255, blue: 229/255, alpha: 1)
button.imageView?.contentMode = .scaleAspectFit
Upvotes: 0
Reputation: 1915
I think the easiest solution is to create a UIImageView as a subview inside the button that you can control however you want.
Upvotes: 0
Reputation: 1287
You can set Image in button Image. will not scale but you can set button as you want. See in the image my button have 100*100 image and button have more size than image.
Upvotes: 1