eemceebee
eemceebee

Reputation: 2666

How to make a +/- button in the iphone sdk?

I hope this question is not too stupid. I need to make a button like the +/- button on the new print function in iOS4.2.

http://www.geeky-gadgets.com/wp-content/uploads/2010/09/Airprint.jpg

alt text

Would that be a segmented control ?

Thanks

Upvotes: 0

Views: 319

Answers (5)

ajay
ajay

Reputation: 3345

If you want to place a button with a +/- symbol, you better try custom button using UIButton class and take a +/- image and place it in your resource folder, then try below code,

  UIButton *button = [[UIButton buttonWithType:UIButtonTypeCustom]initWithFrame:CGRectMake(0, 0,24, 24)];
  [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
  [button setBackgroundImage:[UIImage imageNamed:@"+/-.png"] forState:UIControlStateNormal];
  [self addSubview:button];

Upvotes: -1

Suresh D
Suresh D

Reputation: 4295

Yes, that's segment Control only.
These buttons call discrete buttons. U can change the title of Segment Control like "-" and "+" this like.

alt text

Then u can use addTaget to call specific function and change the copy count....

Upvotes: 4

Alex Brown
Alex Brown

Reputation: 42902

Add an NSSegmentedControl from the Inputs and Values folder in interface builder.

Set the number of segments to two, and set the template of segment0 to NSAddTemplate, and the template of segment1 to NSRemoveTemplate. Set mode to "select none" alt text

Upvotes: 0

ipraba
ipraba

Reputation: 16553

That's a segmented control. Set the title as "+" and "-" for that. Hadle Actions for segmented control as

[segmentedControl addTarget:self
                 action:@selector(action:)
       forControlEvents:UIControlEventValueChanged];

Upvotes: 2

Ishu
Ishu

Reputation: 12787

Yes that is segmented control or you can use a single image having + - (same as your link then add two custom button on that image and now you can able to perform two different functions.

Otherwise use segmented control.

Upvotes: 1

Related Questions