您的位置:首页 > 其它

透明字体如何设置?

2015-12-20 19:47 274 查看
有时会在一些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-

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: