如何设置按钮标题的位置

时间:2016-09-28 06:57:45

标签: ios swift

这里我在按钮的标题上写了阿拉伯语。然后在中心对齐标题标签但问题是一些阿拉伯语后者触及按钮的按钮边界和按钮的一些顶部边界。我是如何解决它的

我的代码是

 optionA.setTitle(Option[0], forState: .Normal)
 optionB.setTitle(Option[1], forState: .Normal)
 optionC.setTitle(Option[2], forState: .Normal)
 optionD.setTitle(Option[3], forState: .Normal)

Hare optionA,optionB,optionC,optionD是按钮,Option是阿拉伯语后者的数组

enter image description here

1 个答案:

答案 0 :(得分:3)

使用此

let button = UIButton(type: .roundedRect)
button.frame = CGRect(x: 20, y: 20, width: 200, height: 72)
button.setTitle("مرحبا", for: .normal)
button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0)
button.contentHorizontalAlignment = .center
self.view.addSubview(button)

并根据需要更改button.titleEdgeInsets

相关问题