本文介绍了无法左对齐 UIButton 标题(iOS/Swift)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在左对齐 UIButton
的文本时遇到问题.我也尝试将其更改为 .Right
但它仍然保持居中.我也试过 aButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 0)
而不是 aButton.titleLabel?.textAlignment = .Left
但这也不会改变任何事情.是否有另一种方法可以以编程方式更改 UIButton
标题的对齐方式?
I'm having a problem left-aligning a UIButton
's text. I also tried changing it to .Right
but it still stays centered. I also tried aButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 0)
instead of aButton.titleLabel?.textAlignment = .Left
but that doesn't change anything either. Is there an alternative way to programmatically change the alignment of a UIButton
title's?
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)
推荐答案
试试这个:
button.contentHorizontalAlignment = .left
这篇关于无法左对齐 UIButton 标题(iOS/Swift)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!