IOS 为Button添加一个提示数量的角标

    xiaoxiao2026-04-01  12

    UIView * homeButtonView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 25, 25)];

    UIImageView * homeButtonImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 25, 25)];

    homeButtonImageView.image = [UIImage imageNamed:@"icon_12"];

    UIButton * homeButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 25, 25)];

     homeButton.backgroundColor = [UIColor clearColor];

     [homeButton addTarget:self action:@selector(tapRightItem) forControlEvents:UIControlEventTouchUpInside];

      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 10, 10)];

      label.text = @"2";

      label.textColor = [UIColor whiteColor];

      label.backgroundColor=[UIColor redColor];

      label.textAlignment = NSTextAlignmentCenter;

      label.layer.cornerRadius=5;

      label.layer.masksToBounds =YES;

      label.font = [UIFont systemFontOfSize:KSCREEN_HEIGHT(11)];

      [homeButton addSubview:label];]

      [homeButtonView addSubview:homeButtonImageView];

      [homeButtonView addSubview:homeButton];

      UIBarButtonItem *homeButtonItem = [[UIBarButtonItem alloc]initWithCustomView:homeButtonView];

      self.navigationItem.rightBarButtonItem=homeButtonItem;

    转载请注明原文地址: https://ju.6miu.com/read-1308379.html
    最新回复(0)