gpt4 book ai didi

swift - 为什么这个 UIButton 没有舍入 Swift?

转载 作者:行者123 更新时间:2023-11-30 11:21:25 24 4
gpt4 key购买 nike

我正在制作这个 UINavigationBarButton,其中的图像最初是方形的。我在其他常规按钮上使用了此代码,它使图像变得圆形。但是,它不适用于此按钮,我不知道为什么。另外,我不知道如何让它变小。 (但不要介意它的位置)

func preloadMe() {

let btn1 = UIButton(type: .custom)
let completelink = self.me[0].picture_url
self.loadProfilePhoto(image: btn1, link: completelink)
btn1.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
btn1.layer.cornerRadius = 0.5 * btn1.frame.height
//btn1.setImage(UIImage(named: "profileMenuButton"), for: .normal)
btn1.addTarget(self, action: #selector(HomeViewController.menuClicked), for: .touchUpInside)
let item1 = UIBarButtonItem(customView: btn1)
btn1.contentEdgeInsets = UIEdgeInsetsMake(0, -70, -10, 0)
self.navigationItem.setLeftBarButtonItems([item1], animated: true)

}

func loadProfilePhoto(image: UIButton, link: String) {
image.downloadedFrom2(link: link)
image.imageView!.clipsToBounds = true
image.imageView!.layer.cornerRadius = (image.imageView!.frame.height) / 2
image.imageView!.contentMode = .scaleAspectFill
}

As you can see in the top left it is still square.

建议添加 btn1.backgroundColor = .black
我现在得到这个结果。我现在应该做什么?

The new result

最佳答案

您的按钮背景颜色为零。这就是为什么绘制上下文不可见的原因。设置按钮背景颜色,您的问题就会得到解决。

btn1.backgroundColor = .black

关于swift - 为什么这个 UIButton 没有舍入 Swift?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51228883/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com