
- #ACCEPTABLE FORMAT OF APPICON IMAGE IN SWIFT HOW TO#
- #ACCEPTABLE FORMAT OF APPICON IMAGE IN SWIFT FULL#
- #ACCEPTABLE FORMAT OF APPICON IMAGE IN SWIFT CODE#
Let backgroundImageBtn:UIButton = UIButton(type: )
#ACCEPTABLE FORMAT OF APPICON IMAGE IN SWIFT HOW TO#
This button will show you how to set an image as a button's background image. Let imageAsBackgroundColorBtn:UIButton = UIButton(type: ) This button will show you how to set an image as a swift button background color. This button will show you how to set an icon image for a button, the image should be an icon type. SwiftSetImageAsButtonIconBackgroundColorExample
#ACCEPTABLE FORMAT OF APPICON IMAGE IN SWIFT FULL#
You can see that the image is not repeatedly displayed, only one image is shown, but the image size is changed to full fill the button’s size.Ĥ.

#ACCEPTABLE FORMAT OF APPICON IMAGE IN SWIFT CODE#
In this example, run the above source code will get the below picture.Set above UIImage object as the button's background image for normal button state.ītBackgroundImage(backgroundImage, for: ) Let backgroundImage:UIImage? = UIImage(named: "gray apple.jpeg") Below is the example swift source code that uses the setBackgroundImage method.You can read the article How To Set Swift Button Background Image Example to learn more. The class UIKit.UIButton provides the setBackgroundImage method, this method can set the button’s background image for different button states.The below picture is the above code execution result, you can see that the image is displayed repeatedly at the button’s background in both directions, and the image size is not changed.ImageAsBackgroundColorBtn.backgroundColor = UIColor(patternImage: backgroundColorImage!) Create a UIColor object with above UIImage object, and set it as the button's backgroundColor. ImageAsBackgroundColorBtn.backgroundColor = UIColor.clear Let backgroundColorImage:UIImage? = UIImage(named: "gray apple.jpeg") Create a UIImage object use image, the image file format is not limited. To do this, just create a UIColor object use a selected UIImage object, then set the UIColor object as the button’s backgroundColor property value.Besides setting the button image icon, you can also set an image as the swift button’s background color.If you do not use an icon format image, then you will see the below picture.The below picture is an example of a swift button with an image icon and text. If you also set the button title text, the text will be located at the icon image right side.

Set above UIImage object as button icon. Let iconImage:UIImage? = UIImage(named: "icons8-apple-logo-96.png") Load an icon format image to a UIImage object. Please note the image format must be an icon format, otherwise, it will show the image incorrectly.
