主要讲解利用UILabel的来做一个简单的toast效果。这个是看到WDLabel的实现,感觉挺好的,就
主要的思路就是继承UILabel,然后在drawRect:(CGRect)rect里面进行调整,以达到一个toast的效果。
#define kLabelCornerRadius 9.0f
- (void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
rect = CGRectInset(rect, 8.0f, 8.0f);
CGContextSetShadow(ctx, CGSizeMake(0, 2), 4); //设置阴影效果
[[UIColor colorWithWhite:0.0f alpha:0.5f] set]; //设置填充颜色半透明
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:kLabelCornerRadius];
[path fill];//填充
[[UIColor whiteColor] set]; //这里主要是设置一个白色的边缘地带
path.lineWidth = 2;
[path stroke];//设置线