iOS 消息小红点

    
    UILabel *label = [[UILabel alloc]init];
    
    label.layer.masksToBounds = YES;
    
    label.layer.cornerRadius = 8;
    
    label.textColor = [UIColor whiteColor];
    
    label.font = [UIFont systemFontOfSize:12];
    
    label.backgroundColor = [UIColor redColor];
    
    label.textAlignment = NSTextAlignmentCenter;
    
    label.text = @"99+";
    
    [label setCenter:CGPointMake(100, 100)];
    
    [label sizeToFit];
    
    NSLog(@"%f",label.frame.size.width);
    
    CGFloat width = label.frame.size.width;
    
    if (width <= 16) {
        [label setFrame:CGRectMake(100, 100, 16, 16)];
    }else {
        
        [label setFrame:CGRectMake(100, 100, width + 2, 16)];
    }
    

    [self.view addSubview:label];
iOS 消息小红点_第1张图片
WechatIMG1314.jpeg

你可能感兴趣的:(iOS 消息小红点)