Hiren Patel
Hiren Patel

Reputation: 135

How to set background image in UIButton of Xamarin.IOS application?

Left side image in UIButton of Xamrin IOS

I have tried the code below but text image gets overlapped.

btnBack.SetImage(UIImage.FromFile("Images/arrow-back.png"), UIControlState.Normal);
btnBack.TintColor = UIColor.White;

Upvotes: 0

Views: 480

Answers (1)

ColeX
ColeX

Reputation: 14475

This is a normal issue when setting text and image simultaneously on Button.

You can use TitleEdgeInsets and ImageEdgeInsets to get rid of it.

For example:

button.ImageEdgeInsets = new UIEdgeInsets(0, -10, 0, 0);
button.TitleEdgeInsets = new UIEdgeInsets(0, 0, 0, -10);

Moreover, you can also create a UIView which contains image and text, in this way it is more controllable.

Upvotes: 1

Related Questions