ios - 在按钮上使用 FFImageLoading 时如何设置内容模式
问题描述
当我使用 FFImageLoading 库设置图像时,我无法让内容模式在按钮上工作。我想将模式设置为 ScaleAspectFill。
我尝试设置 button.imageview 的内容模式以及按钮本身。
button.ContentMode = UIViewContentMode.ScaleAspectFill;
button.ImageView.ContentMode = UIViewContentMode.ScaleAspectFill;
ImageService.Instance.LoadUrl(image_url).Into(button);
图像未缩放并且显示为 ScaleAspectFit 而不是 Fill
解决方案
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:
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.
推荐阅读
- php - php-fpm主进程重启后执行PHP脚本
- oracle - 无法删除 sql developer 中的现有主表
- linux - 我试图通过串口发送命令列表,但设备只占用第一行,其他行被忽略
- javascript - 声明一个全局 google maps 对象
- javascript - 如何通过 HTML 中的开关使用 onchange 更改 BACK
- html - 如何从日期输入字段中删除不需要的标记?
- laravel - “如何修复 laravel 作业已尝试太多次或运行时间过长”
- java - 使用java合并solr中重复的Faceitfields列表
- godot - Godot 3.1 告诉我 lock() 和 get_pixel() 是不存在的函数
- blockchain - 如何使用修剪过的链数据运行 TomoChain 全节点