您的位置:首页 > 移动开发 > IOS开发

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

2016-08-16 11:21 471 查看
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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Button 角标 数量