透明字體如何設置?

有時會在一些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-
這裏寫圖片描述

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