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

标签 swift uibutton title text-alignment leftalign

我在左对齐 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/

相关文章:

某些div内的jQuery属性选择器

android - 如何阻止 Android 选项卡中的标题在单词中间换行?

ios - 如何让 Swift 循环无限期(永远)运行?

ios - 带有未在后台调用的请求 block 的 URLSession.datatask

objective-c - 我想实现一半 UITableView 一半 MapView UIView,中间有一个按钮

xcode - 如何更改按钮大小?

ios - 如何停止 NSTimer?

swift - 在 Swift 中扩展 SCNNode

ios - 如何使用 Swift 在 UICollectionViewCell 中设置 UIButton 的标题

JQuery 工具提示 : Target Span inside title attribute