首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在使用FFImageLoading on按钮时设置内容模式

如何在使用FFImageLoading on按钮时设置内容模式
EN

Stack Overflow用户
提问于 2019-05-28 22:33:45
回答 1查看 84关注 0票数 0

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

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

代码语言:javascript
复制
button.ContentMode = UIViewContentMode.ScaleAspectFill;
button.ImageView.ContentMode = UIViewContentMode.ScaleAspectFill;
ImageService.Instance.LoadUrl(image_url).Into(button);

图像没有缩放,显示为ScaleAspectFit而不是Fill

EN

回答 1

Stack Overflow用户

发布于 2019-05-29 15:52:30

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

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

代码语言:javascript
复制
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);

它们有不同的效果:

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56344550

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档