【问题标题】:Setting the text of a UILabel to an int?将 UILabel 的文本设置为 int?
【发布时间】:2012-03-14 09:28:15
【问题描述】:

这个问题几乎是不言自明的。我需要将 UILabel 实例的 text 属性设置为 int。我该怎么做呢?抱歉,如果这是一个菜鸟问题。

谢谢!

【问题讨论】:

    标签: objective-c text nsstring int uilabel


    【解决方案1】:

    假设你有:

    UILabel *myLabel; //instance of your label
    int myInt; //the integer you need to set as text into UILabel
    

    你可以这样做,而且很简单:

    [myLabel setText:[NSString stringWithFormat:@"%d", myInt]];
    

    或:

    myLabel.text = [NSString stringWithFormat:@"%d", myInt];
    

    【讨论】:

      【解决方案2】:
      NSNumber *number = [NSNumber numberWithInt:yourInt];
      [yourLabel setText:[number stringValue]];
      

      【讨论】:

        【解决方案3】:
        label.text = [NSString stringWithFormat:@"%i",intNumber];
        

        【讨论】:

          【解决方案4】:

          试试这个:

           [label setText:[NSString stringWithFormat:@"%d", intValue]];
          

          【讨论】:

            猜你喜欢
            • 2023-03-08
            • 2014-09-21
            • 2011-12-19
            • 1970-01-01
            • 2010-12-31
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多