【问题标题】:How to show pyramid pattern on UILabel on Button Click(swift language)如何在按钮单击时在 UILabel 上显示金字塔图案(swift 语言)
【发布时间】:2022-08-02 16:00:49
【问题描述】:

///swift iOS /// I have tried with below code

@IBOutlet weak var myLbl: UILabel!



override func viewDidLoad() {
    super.viewDidLoad()
    
    
}
func magic(choose: String, row: Int) -> String {
    var name = \"\"
    
    for i in 1...row {
        
        name +=  (String.init(repeating: \" \", count: row-i)+String.init(repeating: choose, count: 2*i-1))
        
        
    }
    
    return name
}

@IBAction func btnPressed(_ sender: UIButton) {
    
    let result  = magic(choose: \"0\", row: 5)
    myLbl.text  = result
}

请检查图像我得到哪种类型的响应 }[我以这种方式得到输出][1] [1]:https://i.stack.imgur.com/YdV8f.png

we have to show this type of response on my UILabel

    标签: ios swift


    【解决方案1】:

    请打开一个新的游乐场并将以下代码粘贴到:

    import UIKit
    
    let label = UILabel()
    
    label.text = " 0 \n000"      // simple demo text
    label.numberOfLines = 0      // unlimited number of lines
    label.font = .monospacedSystemFont(ofSize: 14, weight: .regular) // monospaced font so that columns are aligned
    label.sizeToFit()            // tell the label to evaluate its content and adjust its size to fit
    
    

    它应该显示您想要的基本示例,并为您提供相应更新代码所需的所有信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-25
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      相关资源
      最近更新 更多