【问题标题】:change the size of the image for the bar button background programatically?以编程方式更改条形按钮背景的图像大小?
【发布时间】:2017-05-03 15:52:51
【问题描述】:

在我的导航栏中,我放置了一个栏按钮,并为背景设置了图像。但是图像的大小比按钮的大小要大得多。所以我试图解决这个问题:

  override func viewDidAppear(_ animated: Bool) {
        let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 5, height: 5 ))
        imageView.contentMode = .center

        let image = UIImage(named: "Info")
        imageView.image = image

        info_btn.image = image
    }

但是图片仍然被拉长。知道我该如何解决吗?

【问题讨论】:

    标签: ios swift image uibarbuttonitem


    【解决方案1】:

    试试info_btn.imageView.contentMode = .scaleAspectFit

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-11
      • 2011-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-15
      相关资源
      最近更新 更多