相关疑难解决方法(0)

麻烦左对齐UIButton标题(iOS/Swift)

我有一个问题是左对齐一个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)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

title uibutton text-alignment leftalign swift

31
推荐指数
2
解决办法
2万
查看次数

标签 统计

leftalign ×1

swift ×1

text-alignment ×1

title ×1

uibutton ×1