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)
基础教程推荐
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01