0

I am not able to get the content mode working on button when I am setting the image using FFImageLoading library.I want to set the mode to ScaleAspectFill.

I tried setting the content mode of the button.imageview as well as the button itself.

button.ContentMode = UIViewContentMode.ScaleAspectFill;
button.ImageView.ContentMode = UIViewContentMode.ScaleAspectFill;
ImageService.Instance.LoadUrl(image_url).Into(button);

The image is not scaling and is appearing as ScaleAspectFit rather than Fill

benin101
  • 131
  • 3
  • 13

1 Answers1

0

Setting the button's ImageView's ContentMode will adjust the image's representation.

I used the code below to display two buttons. One has set the ContentMode and another doesn't:

UIButton btn = new UIButton(UIButtonType.Custom);
btn.Frame = new CoreGraphics.CGRect(50, 100, 100, 40);

btn.ImageView.ContentMode = UIViewContentMode.ScaleAspectFill;
ImageService.Instance.LoadUrl("https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE1Mu3b?ver=5c31").Into(btn);

UIButton btn2 = new UIButton(UIButtonType.Custom);
btn2.Frame = new CoreGraphics.CGRect(50, 200, 100, 40);
ImageService.Instance.LoadUrl("https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE1Mu3b?ver=5c31").Into(btn2);

View.AddSubview(btn);
View.AddSubview(btn2);

They have different effects:

enter image description here

The first button doesn't have enough width to display this image so it clips the left and right edges due to the configuration of content mode. But the second button stretches the image to fit the whole space. Both buttons have the same size.

Ax1le
  • 6,563
  • 2
  • 14
  • 61
  • The first button is what I am looking for. But somehow the image does not scale. I am using the button inside a stack view. So there is no Frame. Does that have anything to do with the issue? I did get it working when I replaced the button with uiimageview. – benin101 May 30 '19 at 06:17
  • @benin101 Can you please offer a sample? – Ax1le May 30 '19 at 06:18