繁体   English   中英

以编程方式更改条形按钮背景图像的大小?

[英]change the size of the image for the bar button background programatically?

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

  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
    }

但是,图片仍然伸出。 知道我该如何解决吗?

尝试info_btn.imageView.contentMode = .scaleAspectFit

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM