美文网首页
文字阴影

文字阴影

作者: Winny_园球 | 来源:发表于2018-04-12 16:32 被阅读0次

    如果给UILabel直接设置下面的代码,效果仅仅只是多了层黑色的阴影而没有渐变模糊的效果

      shadow.shadowOffset = CGSizeMake(.5,.5);
      shadow.shadowColor = [UIColor lightGrayColor];
    

    所以推荐下面这段代码,可以实现渐变模糊效果

        NSShadow * shadow = [[NSShadow alloc]init];
        shadow.shadowBlurRadius = 1.f;
        shadow.shadowOffset = CGSizeMake(.5,.5);
        shadow.shadowColor = [UIColor lightGrayColor];
        
        NSString * message = [NSString stringWithFormat:@"%@:%@",_model.userName,_model.message];
        
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:message attributes:@{NSShadowAttributeName:shadow}];
        
        [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:[message rangeOfString:message]];
        
        self.messageLabel.attributedText = attributedString.copy;
    

    相关文章

      网友评论

          本文标题:文字阴影

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