setBackgroundImage(_:for:barMetrics:)
Sets the background image for given state and bar metrics.
Declaration
func setBackgroundImage(_ backgroundImage: UIImage?, for state: UIControl.State, barMetrics: UIBarMetrics)Parameters
- backgroundImage:
The background image to use for
stateandbarMetrics. - state:
A control state.
- barMetrics:
Bar metrics.
Discussion
If backgroundImage is an image that resizableImage(withCapInsets:) returns, the system calculates the cap widths from that information.
If backgroundImage isn’t an image that resizableImage(withCapInsets:) returns, the system calculates the cap width by subtracting one from the image’s width, then dividing by 2. The system uses the cap widths as the margins for text placement. To adjust the margin, use the margin adjustment methods.
Generally, specify a value for the normal state. The segmented control uses this state for other states that don’t have a custom value set.
Similarly, when a property is dependent on the bar metrics, be sure to specify a value for UIBarMetrics.default. The segmented control respects properties for UIBarMetrics.compact only when the control is in smaller navigation and toolbars.
See Also
Customizing appearance
selectedSegmentTintColorbackgroundImage(for:barMetrics:)contentPositionAdjustment(forSegmentType:barMetrics:)setContentPositionAdjustment(_:forSegmentType:barMetrics:)UISegmentedControl.SegmentdividerImage(forLeftSegmentState:rightSegmentState:barMetrics:)setDividerImage(_:forLeftSegmentState:rightSegmentState:barMetrics:)titleTextAttributes(for:)setTitleTextAttributes(_:for:)