Reputation: 37
In the app that I am making I have some background images for some labels. The image is 500x550 pixels but my label is 250x275 pixels. How can I make the code change the width and height of the background so it fits the size of the label?
Code I have now:
lblMainNumber.backgroundColor = UIColor(patternImage: UIImage(named: "image.png")!)
Upvotes: 2
Views: 969
Reputation: 7466
It is easier to have a container UIView with size of 250 x 275 that will contain 2 subviews with same size:
1) a UIImageView with your image (set its contentMode to UIViewContentModeScaleAspectFit)
2) UILabel with your text. It will be on top of the UIImageView to stay visible.
You would possibly want to set both subviews (via autolayout) to match the size of container view. Pattern image approach is pain in the ass and not wort the effort.
Upvotes: 1