最新微博提示框

本博客展示了如何在iOS应用中通过按钮显示最新微博数量,并提供了友好的用户提示。主要内容包括创建按钮、设置图片与文字、动画移动按钮等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/**
 *  显示最新微博熟练,给用户友善的提示
 */
- (void)showNewStatusCount:(int)count
{
    //1.创建一个按钮,设置到导航栏的下面
    UIButton *btn = [[UIButton alloc] init];
    [self.navigationController.view insertSubview:btn belowSubview:self.navigationController.navigationBar];
    
    //2.设置图片和文字
    btn.userInteractionEnabled = NO;
    [btn setBackgroundImage:[UIImage resizedImageWithName:@"timeline_new_status_background_os7"] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:14];
    [btn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    if (count) {
        [btn setTitle:[NSString stringWithFormat:@"共有%d条新微博",count] forState:UIControlStateNormal];
    }else{
        [btn setTitle:@"没有新的微博" forState:UIControlStateNormal];
    }
    
    //3.设置按钮的初始frame
    CGFloat btnX = 0;
    CGFloat btnH = 30;
    CGFloat btnY = 64 - btnH;
    CGFloat btnW = self.view.frame.size.width;
    btn.frame = CGRectMake(btnX, btnY, btnW, btnH);
    
    //4.动画移动按钮
    [UIView animateWithDuration:0.7 animations:^{
        btn.transform = CGAffineTransformMakeTranslation(0, btnH);
    }completion:^(BOOL finished) {
        //动画执行完毕后
        [UIView animateKeyframesWithDuration:0.7 delay:1.0 options:UIViewKeyframeAnimationOptionCalculationModeLinear animations:^{
            btn.transform = CGAffineTransformMakeTranslation(0, 0);
        } completion:^(BOOL finished) {
            [btn removeFromSuperview];
        }];
    }];

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值