【问题标题】:Create a button made by an icon so that icon is fills it创建一个由图标制作的按钮,以便图标填充它
【发布时间】:2019-02-06 17:10:27
【问题描述】:

如何制作一个没有任何文本但只有图像作为图标的按钮?我已经尝试使用 imageEdset 以这种方式设置按钮:

button.imageEdgeInsets = UIImageEdgeInsets(top: 5, left: 5, bottom: 5, right: 5)

但图像似乎没有居中和拉伸

【问题讨论】:

  • 为什么要设置边缘插图?您希望您的图像看起来如何?
  • @RakeshaShastri 我希望它填充按钮

标签: ios swift uibutton uiimageview


【解决方案1】:

如果你想填充按钮,那么你应该将UIImageViewcontentMode设置为.scaleAspectFill

button.imageView.contentMode = .scaleAspectFill

警告:如果图像纵横比和您的 imageView 纵横比匹配,这只会显示完整的图像。

如果要显示完整图像,则应将contentMode 设置为.scaleAspectFit

button.imageView.contentMode = .scaleAspectFit

【讨论】:

    猜你喜欢
    • 2017-10-21
    • 1970-01-01
    • 1970-01-01
    • 2015-10-13
    • 1970-01-01
    • 2023-01-12
    • 2022-09-28
    • 2023-01-18
    • 1970-01-01
    相关资源
    最近更新 更多