Trouble left-aligning UIButton title (iOS/Swift)(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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UIButton 标题左对齐问题 (iOS/Swift)
- GPS状态的广播接收器? 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- URL编码Swift iOS 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- UITextView 内容插图 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01