Duplicating buttons in XCode

7.2k views Asked by At

I have a relatively simple problem (and yes I am a noob to iphone app development) but I am unsure how to continue.

I have a complex button design that I need to repeat a lot and relocate on the screen.

Should I create a class that takes input of label and location and returns the button or is there a way to simply create the custom button and duplicate it?

If people could suggest which way is best (or even better ways) and how best to go about it I would really appreciate it.

Thanks

2

There are 2 answers

0
devsri On

You can do that by simply copying the button in IB using command + c in your MAC and then command + v to paste the same. This approach could be followed if you know the exact number of buttons you require in the final design. Do remember to change the IBOulet and IBAction of the new copied buttons as they will possess the same property as the button from which they were copied.

In case you want to create it dynamically then can run a loop in -(void)loadView{} method or in anyother method depending on your requirements. You can use addTarget:action:forControlEvents: method to set the target of the UIButton

Hope it helps!!

0
Owls On

There are different approaches for this. For quick use, you can just click alt key and drag the button you want to duplicate. Even command + c and command + v works well. It really depends on to use which method you want.