gpt4 book ai didi

swift - 问题左对齐 UIButton 标题 (iOS/Swift)

转载 作者:IT王子 更新时间:2023-10-29 05:04:35 24 4
gpt4 key购买 nike

我在左对齐 UIButton 的文本时遇到问题。我也尝试将其更改为 .Right 但它仍然居中。我还尝试了 aButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 0) 而不是 aButton.titleLabel?.textAlignment = .Left但这也没有改变任何东西。是否有替代方法以编程方式更改 UIButton 标题的对齐方式?

        allButtonViews = UIView(frame: CGRectMake(0, 44, 100, 100))
allButtonViews.backgroundColor = .redColor()

let campusButton = UIButton(type: UIButtonType.System) as UIButton
aButton.frame = CGRectMake(0, 0, 300, 70)
aButton.setTitle("A", forState: .Normal)
aButton.titleLabel?.textColor = .blueColor()
aButton.titleLabel?.textAlignment = .Left
aButton.backgroundColor = .whiteColor()

sortView.addSubview(aButton)
view.addSubview(allButtonViews)

enter image description here

最佳答案

试试这个:

button.contentHorizontalAlignment = .left

关于swift - 问题左对齐 UIButton 标题 (iOS/Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36464708/

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