iPhone开发技巧之私有API--- UIBarButtonItem

http://www.yifeiyang.net/iphone-development-skills-of-the-private-api-4-uibarbuttonitem/


今天介绍一下 UIBarButtonItem 的特殊用法。

UIBarButtonItem

如上所示,UIBarButtonSystemItem 的 100 ~ 110 就是系统提供的一些未公开的标准icon。

2
3
4
5
6
7
8
9
10
11
12
13
14
15

	

NSMutableArray *items = [NSMutableArray array];
UIBarButtonItem *item = nil;
for (int i = 100; i <= 109; i++) {
    item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:i target:nil action:nil];
    item.style = UIBarButtonItemStyleBordered;
    [items addObject:item];
    [item release];
}

item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:110 target:nil action:nil];
item.style = UIBarButtonItemStylePlain;
[items addObject:item];
[item release];

toolbar.items = items;



  • 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、付费专栏及课程。

余额充值