【问题标题】:How to set content mode when using FFImageLoading on button在按钮上使用 FFImageLoading 时如何设置内容模式
【发布时间】:2019-10-14 02:53:33
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: ios xamarin.ios ffimageloading


    【解决方案1】:

    设置按钮的 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);
    

    它们有不同的效果:

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

    【讨论】:

    • 第一个按钮是我要找的。但不知何故,图像无法缩放。我正在使用堆栈视图中的按钮。所以没有框架。这和问题有关系吗?当我用 uiimageview 替换按钮时,我确实让它工作了。
    • @benin101 能否提供样品?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多