我在将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)

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

最佳答案

尝试这个:

button.contentHorizontalAlignment = .left

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

10-11 02:38