Ios上任意控件上添加自定义Badge

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

-(CATextLayer *)creatBadgeLayer{

     CATextLayer *badgeLayer = [[CATextLayer alloc] init];
    badgeLayer.backgroundColor=[UIColor redColor].CGColor;
    badgeLayer.foregroundColor = [UIColor whiteColor].CGColor;
    badgeLayer.alignmentMode = kCAAlignmentCenter;
    [badgeLayer setFrame:CGRectMake(0, 0, 18, 18)];
    badgeLayer.position=CGPointMake(20, 3);
    badgeLayer.wrapped = YES;
    badgeLayer.cornerRadius = 9.0f;
    [badgeLayer setFontSize:13];
    [badgeLayer setString:@"1"];
    badgeLayer.anchorPoint=CGPointZero;
    badgeLayer.contentsScale = [[UIScreen mainScreen] scale];
    
    return badgeLayer;
}
//给控件添加badge
[btn.layer addSublayer:[self creatBadgeLayer]];


转载于:https://my.oschina.net/u/2532565/blog/538324

你可能感兴趣的:(Ios上任意控件上添加自定义Badge)