美文网首页
iOS 消息小红点

iOS 消息小红点

作者: Luyc_Han | 来源:发表于2018-01-05 10:12 被阅读189次
    
    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];
WechatIMG1314.jpeg

相关文章

网友评论

      本文标题:iOS 消息小红点

      本文链接:https://www.haomeiwen.com/subject/bpyjnxtx.html