gpt4 book ai didi

ios - 在 UIButton 上同时显示图像和标题 - Swift 3

转载 作者:搜寻专家 更新时间:2023-11-01 05:56:07 25 4
gpt4 key购买 nike

如何在 UIbutton 上同时显示标题和图像?我试着关注 Display image and text in Button它使用 swift 2,但相同的过程仅在 swift 3 中显示图像,标题被隐藏。图像源文件为 35x35 像素。我的代码:

  let folderButton = UIButton(frame: CGRect(x: 100 , y: 200, width: 200, height: 41))
folderButton.layer.borderColor = UIColor.black.cgColor
folderButton.layer.borderWidth = 1
folderButton.imageEdgeInsets = UIEdgeInsets(top: 0,left: 162,bottom: 3,right: 3)
folderButton.titleEdgeInsets = UIEdgeInsets(top: 0,left: 0,bottom: 0,right: 41)
folderButton.setImage(UIImage(named:"FolderIcon35"), for: UIControlState.normal)
folderButton.setTitle("Test", for: UIControlState.selected)
folderButton.setTitleColor(.black, for: .normal)
view.addSubview(folderButton)

current Output

需要一个程序化的解决方案,因为我没有使用 Storyboard。谢谢!

最佳答案

我认为你应该为 UIControlState.normal 设置标题

folderButton.setTitle("Test", for:.normal)

关于ios - 在 UIButton 上同时显示图像和标题 - Swift 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43908717/

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