How to make menu dynamically in iphone using programming?

Leave a Comment
Menu control in iphone is completely implemented here. I will give you small code snippets for you. So you can easily understand it .

devangViewController .h header file
#import <UIKit/UIKit.h>
@interface devangViewController : UIViewController
- (IBAction)ddMenuShow:(UIButton *)sender;
- (IBAction)ddMenuSelectionMade:(UIButton *)sender;
@property (nonatomic, strong) IBOutlet UIView *ddMenu;
@property (nonatomic,strong) IBOutlet UIButton *ddmenushowbutton;
@property (weak, nonatomic) IBOutlet UILabel *menu_lbl;
@end 

devangViewController.m implementation

  #import "devangViewController.h"
@interface devangViewController ()
@end
@implementation devangViewController
@synthesize ddMenu,menu_lbl;
@synthesize ddmenushowbutton;
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.ddMenu.hidden=YES;
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)ddMenuShow:(UIButton *)sender
{
    if (sender.tag == 0) {
        sender.tag = 1;
        self.ddMenu.hidden = NO;
        [sender setTitle:@"" forState:UIControlStateNormal];
    } else {
        sender.tag = 0;
        self.ddMenu.hidden = YES;
        [sender setTitle:@"" forState:UIControlStateNormal];
    }
}
- (IBAction)ddMenuSelectionMade:(UIButton *)sender
{
 
 
 
    self.ddMenu.hidden = YES;
 
    [self.ddmenushowbutton setTitle:@"" forState:UIControlStateNormal];
    self.ddmenushowbutton.tag = 0;
    switch (sender.tag) {
        case 1:
        {
            menu_lbl.text=sender.titleLabel.text;
            break;
        }
        case 2:
        {
            menu_lbl.text=sender.titleLabel.text;
            break;
         
         
        }
        case 3:
        {
           menu_lbl.text=sender.titleLabel.text;
            break;
         
        }
        case 4:
        {
            menu_lbl.text=sender.titleLabel.text;
            break;
         
        }
         
        default:
            break;
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
 This is very easy way to implement this type of menu control in iphone.

output:





Download Source Code


0 comments:

Post a Comment