user3159667
user3159667

Reputation: 19

How to assign negative value to UIButton Tag ?

How to create UIButton dynamically in iOS.

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

I have tried this code. My Question is can I give negative value for tag value? Like

btn.setTag=-2;

Is it possible to set it in dynamic UIButton ?

Upvotes: 0

Views: 550

Answers (2)

Mani
Mani

Reputation: 17595

Yes, you can set. Because tag type is NSInteger. If it is NSUInteger means, you cann't set. But in this, you can.

But instead of btn.setTag=-2;, btn.tag = -2. You can do like this.(it will explicitly call [btn setTag:-2] via setter method.)

Upvotes: 1

Dharmbir Singh
Dharmbir Singh

Reputation: 17535

Yes, You can set in 2 ways...

First Solution

btn.tag=-2; // -------- this is property ----------


Second Solution

[btn setTag:-2];  // -------- this is method ----------

Upvotes: 1

Related Questions