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)
基础教程推荐
- 在视图控制器的宽度上水平均匀分布 UIButton 的最简单方法? 2022-01-01
- UINavigationItem 的持久 rightBarButtonItem 属性 2022-01-01
- Android - 如何在runOnUiThread 中将数据传递给Runnable? 2022-01-01
- UINavigationBar 隐藏按钮文本 2022-01-01
- 在 iOS 7 下 CCMenu 错位 2022-01-01
- 更改 UITableView 部分标题的颜色 2022-01-01
- EditText 中的 setHintTextColor() 2022-01-01
- 从 UIWebView 访问元数据 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Firebase 云消息传递令牌未生成 2022-01-01