【问题标题】:How to assign negative value to UIButton Tag ?如何为 UIButton Tag 分配负值?
【发布时间】:2014-01-04 07:05:12
【问题描述】:

如何在 iOS 中动态创建 UIButton。

UIButton *btn=[[UIButton alloc]init];
btn.frame=CGRectMake(0,20,30,30);
btn.setTag=2;
[self.view addSubView:btn];

我已经尝试过这段代码。我的问题是我可以给标签值负值吗?喜欢

btn.setTag=-2;

是否可以在动态 UIButton 中设置?

【问题讨论】:

    标签: ios tags uibutton


    【解决方案1】:

    是的,您可以设置。因为tag 类型是NSInteger。如果是NSUInteger的意思,你cann't设置。但在这方面,你可以。

    但不是btn.setTag=-2;,而是btn.tag = -2。你可以这样做。(它将通过setter方法显式调用[btn setTag:-2]。)

    【讨论】:

      【解决方案2】:

      是的,您可以通过 2 种方式进行设置...

      First Solution
      
      btn.tag=-2; // -------- this is property ----------
      
      
      Second Solution
      
      [btn setTag:-2];  // -------- this is method ----------
      

      【讨论】:

        猜你喜欢
        • 2014-03-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-20
        • 1970-01-01
        • 2012-09-27
        • 1970-01-01
        • 2023-04-01
        相关资源
        最近更新 更多