Reputation: 5830
I need a custom button like Instragram has in profile tab (the buttons that shows the number of photos and followers) but i don't know how to start to implement it. Do i need to subclass UIButton or is there other way easier?
Upvotes: 1
Views: 1334
Reputation: 52227
I think, the easiest approach would be to create a UIButtom with the typeUIButtonTypeCustom
and add a subview to it with imageviews and labels as subviews to create the UI. Composition over inheritance.
Upvotes: 3
Reputation: 1064
Subclassing UIButton seems to me to be the obvious solution. I agree that subclassing UIViewController makes no sense. You don't use UIViewController objects to manipulate individual subviews within a view hierarchy controlled by another UIViewController object.
Upvotes: 1
Reputation: 622
There are plenty of ways to do this, personally I would subclass UIViewController. Then you can edit its .xib in interface builder to make it look however you want and set different values programmatically. Then to detect a tap on the button you can just use the touchesBegan and touchesEnded (I'm pretty sure those aren't complete method names, check in the docs for more info on them) methods. If you want you could also set up a UITapGestureRecognizer for the view instead.
Upvotes: 0