gpt4 book ai didi

ios - 在按钮上使用 FFImageLoading 时如何设置内容模式

转载 作者:行者123 更新时间:2023-11-29 05:43:38 24 4
gpt4 key购买 nike

当我使用 FFImageLoading 库设置图像时,我无法使内容模式在按钮上工作。我想将模式设置为 ScaleAspectFill。

我尝试设置button.imageview的内容模式以及按钮本身。

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

图像未缩放,并且显示为 ScaleAspectFit 而不是 Fill

最佳答案

设置按钮的 ImageView 的 ContentMode 将调整图像的表示。

我使用下面的代码来显示两个按钮。一个已设置 ContentMode,另一个未设置:

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);

它们有不同的效果:

enter image description here

第一个按钮没有足够的宽度来显示该图像,因此由于内容模式的配置,它会剪裁左右边缘。但第二个按钮会拉伸(stretch)图像以适合整个空间。两个按钮的大小相同。

关于ios - 在按钮上使用 FFImageLoading 时如何设置内容模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56344550/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com