点击navigationitem上的按钮,弹出view,类似弹出菜单

推荐示例点击打开链接,下载需要引入的MLKMenuPopover.h/m文件


示例图片如下:

1.引入MLKMenuPopover.h/m文件,MLKMenuPopover.h在上述连接中,自己下载。

2.实现MLKMenuPopoverDelegate协议

3.定义@property(nonatomic,strong) MLKMenuPopover *menuPopover;
        @property(nonatomic,strong) NSArray *menuItems;

4.在viewDidLoad中写:

 self.menuItems = [NSArray arrayWithObjects:@"第一条", @"第二条",@"第三条", nil];
    UIBarButtonItem *right=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(BarShow)];
    UIBarButtonItem *right1=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed: @"group_member_type.png"]  style:UIBarButtonItemStylePlain target:self action:@selector(BarShow)];
    [self.navigationItem setRightBarButtonItem:right1];

5.实现navigationItem 的BarShow方法

  self.menuPopover = [[MLKMenuPopover alloc] initWithFrame:CGRectMake(160, 70, 140, 140) menuItems:self.menuItems];
    self.menuPopover.menuPopoverDelegate = self;
    [self.menuPopover showInView:self.view];

6.实现协议的方法  这里实现自己想干的事情

- (void)menuPopover:(MLKMenuPopover *)menuPopover didSelectMenuItemAtIndex:(NSInteger)selectedIndex
{
    [self.menuPopover dismissMenuPopover];
    
    NSString *title = [NSString stringWithFormat:@"%@ selected.",[self.menuItems objectAtIndex:selectedIndex]];
    
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    
    [alertView show];
}

ok,大功告成

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,根据您的要求,我来为您提供Objective-C纯代码编写右上角倒计时跳转按钮的实现方法。 首先,在您的ViewController中创建一个计时器,代码如下: ``` @interface ViewController () @property (nonatomic, strong) NSTimer *timer; @property (nonatomic, assign) NSInteger timeCount; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.timeCount = 60; // 设置倒计时总时间 [self setupRightBarButton]; [self startTimer]; } - (void)setupRightBarButton { UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom]; [rightButton setTitle:@"60s" forState:UIControlStateNormal]; [rightButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; [rightButton addTarget:self action:@selector(rightBarButtonClicked) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton]; self.navigationItem.rightBarButtonItem = rightItem; } - (void)rightBarButtonClicked { // 跳转到其他页面 } - (void)startTimer { self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerCountdown) userInfo:nil repeats:YES]; [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes]; } - (void)timerCountdown { self.timeCount--; if (self.timeCount <= 0) { [self.timer invalidate]; self.timer = nil; self.navigationItem.rightBarButtonItem.enabled = YES; self.timeCount = 60; UIButton *button = (UIButton *)self.navigationItem.rightBarButtonItem.customView; [button setTitle:@"60s" forState:UIControlStateNormal]; } else { UIButton *button = (UIButton *)self.navigationItem.rightBarButtonItem.customView; [button setTitle:[NSString stringWithFormat:@"%lds", (long)self.timeCount] forState:UIControlStateNormal]; } } @end ``` 在这段代码中,我们创建了一个计时器来进行倒计时。在 `setupRightBarButton` 方法中,我们创建了一个 `UIButton` 作为 `UIBarButtonItem` 的 `customView`,并设置了它的标题为倒计时的时间。在 `startTimer` 方法中,我们启动了计时器,并设置了它的时间间隔为1秒。在 `timerCountdown` 方法中,我们对时间进行了倒计时,并更新了按钮的标题。当时间到达0时,我们停止了计时器,并将按钮的标题设置为60秒。 当用户点击右上角的按钮时,会跳转到其他页面,您可以在 `rightBarButtonClicked` 方法中进行相应的处理。 希望这段代码能够帮助到您!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值