Kyle Clegg
Kyle Clegg

Reputation: 39480

Add a custom UI Object (UISwitch) to an iOS project

I'm trying to add a custom UISwitch to my app using DCRoundSwitch, however I'm struggling to figure out how to implement it correctly. After adding the files to my project I went to change my UISwitch to a DCRoundSwitch but have run into several problems, including the unrecognized selector sent to instance error.

I've tried (1) going to the Xib, selecting the Switch, opening the identity selector and changing the custom class, but the only option I see is UISwitch. (2) I've also tried changing the UISwitch to DCRoundSwitch in the code, but that results in the error mentioned above when I run it.

I feel like I'm missing a step, but I'm not sure what. Do I need to delete the switch and re-add the new switch? I've never done this programmatically before.

Upvotes: 0

Views: 1488

Answers (3)

Kyle Clegg
Kyle Clegg

Reputation: 39480

Finally found a solution!

The way to add a custom UI object in IB (after adding the code to your project) is to drag a generic UIView object onto your Xib, resize it as needed, then switch to the identity inspector and change the class from UIView to DCRoundSwitch (or other custom object).

Caveat: If you don't see your custom object listed, try building your project or closing and re-opening xCode. xCode 4 and up should recognize it after you've added your code to compiled sources.

Upvotes: 2

hightech
hightech

Reputation: 3760

Have you seen this? https://github.com/robertchin/rcswitch (I used that sample for my apps)

Upvotes: 0

bitmapdata.com
bitmapdata.com

Reputation: 9600

DCRoundSwitch is not UISwitch Custom Class. this is a inherited from UIControl. this mean is in interface builder you not set UISwitch CustomClass. UISwitch between DCRoundSwitch is not related at all. so you must set Programmatically.

Upvotes: 0

Related Questions