【发布时间】:2013-09-02 11:49:00
【问题描述】:
我正在尝试制作一个 UILabel,其边缘如下图所示。
这是来自我的UILabel 子类的drawRect:。
-(void)drawRect:(CGRect)rect{
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGRect labelRect = self.bounds;
CGPoint bottomPoint = CGPointMake(labelRect.size.width, rect.size.height);
CGPoint topMinus30Point =CGPointMake(labelRect.size.width-30, 0);
CGPoint topPoint = CGPointMake(labelRect.size.width, 0);
CGContextBeginPath (context);
//from bottom to -30 top
CGContextMoveToPoint(context, bottomPoint.x,bottomPoint.y);
CGContextAddLineToPoint(context, topMinus30Point.x,topMinus30Point.y);
//from -30 to top
CGContextMoveToPoint(context, topMinus30Point.x,topMinus30Point.y);
CGContextAddLineToPoint(context, topPoint.x,topPoint.y);
//from top to bottom
CGContextMoveToPoint(context, topPoint.x,topPoint.y);
CGContextAddLineToPoint(context, bottomPoint.x,bottomPoint.y);
CGContextClosePath(context);
CGContextStrokePath(context);
CGContextRestoreGState(context);
}
如何从当前帧裁剪创建的路径?
[我刚刚开始使用 Core Graphics,所以请温柔:)]
任何关于如何实现这一点的指示都会非常有帮助。
谢谢
【问题讨论】:
-
你正在寻找的愚蠢的东西......你可以通过这样的方式来设置背景图像,该图像具有该切角,并在该图像视图上方添加 UILable 与您想要的文本......那里无法实现您的要求
-
我总是可以用图像做到这一点,但这是我核心图形研究的一部分。
-
你想让裁剪的部分透明吗?
标签: iphone ios objective-c cocoa-touch core-graphics