答案 0 :(得分:0)
您应该设计UIView的自定义类并设置如下代码:
#import "popoverView.h"
@implementation popoverView
- (void)drawRect:(CGRect)rect {
self.layer.cornerRadius=6.0;
CGFloat margian=20;
[self addpathAtPoint:CGPointMake(margian, margian) andEndPoint:CGPointMake(sqrtf(margian*margian+margian*margian), 0.0)];
[self addpathAtPoint:CGPointMake(sqrtf(margian*margian+margian*margian), 0.0) andEndPoint:CGPointMake(2*margian, margian)];
[self addpathAtPoint:CGPointMake(2*margian, margian) andEndPoint:CGPointMake(rect.size.width-2*margian, margian)];
[self addCurveToPoint:CGPointMake(rect.size.width-2*margian, margian) endPoint:CGPointMake(rect.size.width-margian, 2*margian) controlPoint1:CGPointMake(rect.size.width-margian, margian) controlPoint2:CGPointMake(rect.size.width-margian, margian)];
[self addpathAtPoint:CGPointMake(rect.size.width-margian, 2*margian) andEndPoint:CGPointMake(rect.size.width-margian, rect.size.height-2*margian)];
[self addCurveToPoint:CGPointMake(rect.size.width-margian, rect.size.height-2*margian) endPoint:CGPointMake(rect.size.width-2*margian, rect.size.height-margian) controlPoint1:CGPointMake(rect.size.width-margian, rect.size.height-margian) controlPoint2:CGPointMake(rect.size.width-margian, rect.size.height-margian)];
[self addpathAtPoint:CGPointMake(rect.size.width-2*margian, rect.size.height-margian) andEndPoint:CGPointMake(2*margian,rect.size.height-margian)];
[self addCurveToPoint:CGPointMake(2*margian,rect.size.height-margian) endPoint:CGPointMake(margian,rect.size.height-2*margian) controlPoint1:CGPointMake(margian, rect.size.height-margian) controlPoint2:CGPointMake(margian, rect.size.height-margian)];
[self addpathAtPoint:CGPointMake(margian,rect.size.height-2*margian) andEndPoint:CGPointMake(margian,margian)];
}
-(void)addpathAtPoint:(CGPoint)startPoint andEndPoint:(CGPoint)endPoint{
UIBezierPath *path=[UIBezierPath bezierPath];
path.lineWidth=3.0;
[path moveToPoint:startPoint];
[path addLineToPoint:endPoint];
[[UIColor blackColor] setStroke];
[path stroke];
[path closePath];
}
-(void)addCurveToPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint controlPoint1:(CGPoint)controlPoint1 controlPoint2:(CGPoint)controlPoint2
{
UIBezierPath *path=[UIBezierPath bezierPath];
path.lineWidth=3.0;
[path moveToPoint:startPoint];
[path addCurveToPoint:endPoint controlPoint1:controlPoint1 controlPoint2:controlPoint2];
[[UIColor blackColor]setStroke];
[path stroke];
}