Swift: 让数字从右到左开始

问题描述 投票:-1回答:1

我目前正在实现一个足球表,上面显示了各队的数据。我使用光学格式来设置视图。在下面的图片中看到。但是你可以看到数字是从左边开始,然后向右扩展。我想要的是,小数字从右边开始,然后向左扩展。

有什么方法可以做到这一点,是否有比使用光学格式更好的方法,因为你可以看到我的代码非常长,而且很乱?

图片中的数字从错误的一端开始。

Wrong picture

我的代码:

addConstraintsWithFormat(format: "H:|-8-[v0(30)]-16-[v1(28)]-12-[v2(70)]-15-[v3(15)]-28-[v4(15)]-25-[v5(15)]-10-[v6(15)]-10-[v7(15)]-16-[v8(40)]-8-[v9(20)]", views: tablePlaceLabel, teamLogoLabel, teamNameLabel, gamesPlayedLabel, pointsLabel, winLabel, drawLabel, losLabel, goalsLabel, goalsDiffLabel) 

扩展:

extension UIView {
func addConstraintsWithFormat(format: String, views: UIView...) {
    var viewsDictionary = [String: UIView]()

    for (index, view) in views.enumerated() {
        let key = "v\(index)"
        view.translatesAutoresizingMaskIntoConstraints = false
        viewsDictionary[key] = view
    }

    addConstraints(NSLayoutConstraint.constraints(withVisualFormat: format, options: NSLayoutConstraint.FormatOptions(), metrics: nil, views: viewsDictionary))
}
}
swift uicollectionview
1个回答
0
投票

你可以用这段代码设置文本对齐方式。

label.textAlignment = .right
© www.soinside.com 2019 - 2024. All rights reserved.