透明字体如何设置?

有时会在一些APP上看到透明字体, 感觉非常漂亮, 那么透明字体如何设置呢?

思路: 能显示字体, 当然是用label, 那么接下来我们自定义label–> EJLabel, 使用drawRect方法将透明字体画上去:

- (void)drawRect:(CGRect)rect{
    CGContextRef ctx = UIGraphicsGetCurrentContext();

    CGRect viewBounds = self.bounds;
    CGContextTranslateCTM(ctx, 0, viewBounds.size.height);
    CGContextScaleCTM(ctx, 1, -1);

    CGContextSetBlendMode(ctx, kCGBlendModeCopy);
    CGContextSetRGBFillColor(ctx, 1.0, 1.0, 1.0, 0.0);
    CGContextSetLineWidth(ctx, 2.0);
    CGContextSelectFont(ctx, "Helvetica", 17.0, kCGEncodingMacRoman);
    CGContextSetCharacterSpacing(ctx, 1.7);
    CGContextSetTextDrawingMode(ctx, kCGTextFill);
    CGContextShowTextAtPoint(ctx, 0, 50, "Paradise", 8);

}

接下来切换到要显示透明字体的视图控制器中:

- (void)viewDidLoad {

    [super viewDidLoad];
    self.view.backgroundColor = [UIColor greenColor];

    EJLabel *label = [[EJLabel alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
    label.backgroundColor = [UIColor orangeColor];
    label.alpha = 0.5;

    [self.view addSubview:view];
}

色彩搭配有点丑 -J-
这里写图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章