【发布时间】:2021-05-16 12:01:46
【问题描述】:
我正在尝试构建一个类似单选按钮的按钮(左侧有一个圆点,旁边是文本 它在右边),很像这样:
我有 2 个 PDF (link to one of them),其中包含选定和未选定收音机的图像。我的按钮代码如下:
let radioBtn = UIButton()
radioBtn.setImage(UIImage(named: "radio", in: .module, compatibleWith: nil), for: .normal)
radioBtn.setImage(UIImage(named: "radio_ticked", in: .module, compatibleWith: nil), for: .selected)
radioBtn.contentHorizontalAlignment = .leading
radioBtn.titleLabel?.adjustsFontSizeToFitWidth = true
radioBtn.titleEdgeInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 0)
radioBtn.contentEdgeInsets = UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0)
radioBtn.heightAnchor.constraint(equalToConstant: 40).isActive = true
radioBtn.contentVerticalAlignment = .center
radioBtn.imageView?.contentMode = .scaleAspectFit
问题是 UIImage 延伸到整个宽度(蓝色部分)并且没有空间供您显示文本:
我想要完成的是完全在左边的收音机,然后是它旁边的文字和一些插图。如何实现?
【问题讨论】:
标签: ios swift uibutton uiimageview uiimage