花的构成
花由四个半圆组成
UIBezierPath
- (void)drawRect:(CGRect)rect {
// Drawing code
CGSize size = self.bounds.size;
CGFloat margin = 10;
CGFloat radius = rintf(MIN(size.height-margin, size.width-margin)/4); //半径
CGFloat xOffset, yOffset;
CGFloat offset = rintf((size.height-size.width)/2);
if (offset > 0) {
xOffset = rintf(margin/2);
yOffset = offset;
}
else {
xOffset = -offset;
yOffset = rint(margin/2);
}
//填充颜色
[[UIColor redColor] setFill];
//初始化
UIBezierPath *path = [UIBezierPath bezierPath];
/*
参数一:圆心
参数二:半径
参数三:开始位置,弧度
参数四:结束弧度
参数五:yes顺时针,no逆时针
*/
[path addArcWithCenter:CGPointMake(radius*2 +xOffset, radius+yOffset) radius:radius startAngle:-M_PI endAngle:0 clockwise:YES];
[path addArcWithCenter:CGPointMake(radius*3+xOffset, radius*2+yOffset) radius:radius startAngle:-M_PI_2 endAngle:M_PI_2 clockwise:YES];
[path addArcWithCenter:CGPointMake(radius*2+xOffset, radius*3+yOffset) radius:radius startAngle:0 endAngle:M_PI clockwise:YES];
[path addArcWithCenter:CGPointMake(radius+xOffset, radius*2+yOffset) radius:radius startAngle:M_PI_2 endAngle:-M_PI_2 clockwise:YES];
[path closePath];
//填充
[path fill];
}