简体   繁体   中英

Add UIView at a UIButton

Here is the requirement of my application:

There is a calendar type view which will show Date, Day, Total work hours of that day. What I need, when I click anywhere in that particular square block then it redirects my page to a new view.

I am thinking to should add multiple button and UIView on that button. That can solve my problem but it is little bit problematic. How should I to do this?

Create a subclass of UIControl and a XIB with a UIView in it. Set the class type for the UIView to your new UIControl (not the file owner but the UIView). Then in the UIControl in the initWithCoder: method create the display component and add to view. Then set up you properties that you need to populate those controls.

To use this new control place a UIView where you want it on your screen and size it. Change its class type (in the inspector) to your new subclass. Now you can add outlets and actions to this view just like you would a UIButton. The only downfall is can't set the display controls from the inspector, you'll have to do that in the program. But the good side is you get a similar interface to a button and you can make it look anyway you like.

Hope this helps.

Please look at UITapGestureRecognizer for your view. I think this is what you're looking for.

Here is a link to a tutorial on using UITapGestureRecognizer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM