一. UIBezierPath
http://www.henishuo.com/uibezierpath-draw/
1 .线颜色
@property CGColorRef strokeColor
2.填充色
@property CGColorRef fillColor
3. 填充规则
@property (copy) NSString *fillRule
4. 线端点类型
@property (copy) NSString *lineCap
5.线连接类型
@property (copy) NSString *lineJoin
6.线宽
@property CGFloat lineWidth
@property (copy) NSArray *lineDashPattern
这是一个NSNumber的数组,索引从1开始记,奇数位数值表示实线长度,偶数位数值表示空白长度
8.线型模板的起始位置
@property CGFloat lineDashPhase
9.最大斜接长度
@property CGFloat miterLimit
只有lineJoin属性为KCALineJoinMiter时miterLimit才有效
边角的角度越小,斜接长度就越大
为了避免斜接长度过长,我们可以使用miterLimit属性
如果斜接长度超过miterLimit的值,边角会以lineJoin的“bevel”即kCALineJoinBevel类型来显示
10. 部分绘线
@property CGFloat strokeStart
@property CGFloat strokeEnd
二. UIBezierPath 贝塞尔曲线的常用绘图方法
1.矩形
+(UIBezierPath *)bezierPathWithRect:(CGRect)rect
2.矩形内切椭圆
+(UIBezierPath)bezierPathWithOvalInRect:(CGRect)rect
3.圆角矩形
+(UIBezierPath *)bezierPathWithRoundedRect:(CGRect)rect cornerRadius:(CGFloat)cornerRadius
4.可设置的圆角矩形
+(UIBezierPath *)bezierPathWithRoundedRect:(CGRect) rect byRoundingCorners: (UIRectCorner) corners cornerRadii:(CGSize) cornerRadii
corners有一下几种类型:
UIRectCornerTopLeft,
UIRectCornerTopRight,
UIRectCornerBottomLeft,
UIRectCornerBottomRight,
UIRectCornerAllCorners
cornerRadii表示的是四个圆角平成的椭圆的长、短半径尺寸
5.圆弧
+(UIBezierPath *)bezierPathWithArcCenter:(CGPoint) center radius:(CGFloat)radius startAngle:(CGFloat)startAngle endeAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise
-(void)addArcWithCenter:(CGPoint)center radius:(CGFloat) radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise
-(void)addLineToPoint:(CGPoint)point
7.曲线
-(void)addCurveToPoint:(CGPoint)endPoint controlPoint1:(CGPoint)controlPoint1 controlPoint2:(CGPoint)controlPoint2
8.二元曲线
-(void)addQuadCurveToPoint=(CGPoint)endPoint controlPoint:(CGPoint)controlPoint
UIBezierPath的属性设置(这些属性在使用CAShapeLayer时,只遵循CAShapeLayer的设置)
1.线宽
@property(nonatomic) CGFloat lineWidth
@property(nonatomic) CGLineCap lineCapStyle
@property(nonatomic) CGLineJoin LineJoinStyle
-(void)setLineDash:(const CGFlot *)pattern count:(NSInteger)count phase:(CGFloat)phase
pattern: C类型的线型。 如:(CGFloat dashStyle[]={1.0f,2.0f);
count:pattern 中的数据个数
phase:开始画线型的起始位置
CAGradientLayer
产生平滑过渡色
interface ViewController ()
@property (nonatomic,weak) IBOutlet UIView * containerView;
@end
@implementation ViewController
-(void)viewDidLoad{
[sepr viewDidLoad];
CAGradientLayer *gradientLayer=[CAGradientLayer layer];
gradientLayer.frame=self.countainerView.bounds;
[self.containerView.layer addSublayer:gradientLayer];
// set gradient colers
gradientLayer.colors=@[(_bridge id) [UIColor redColor].CGColor, (_bridge id) [UIColor blueColor].CGColor];
// set gradient start and points
gradientLayer.startPoint=CGPointMake(0,0);
gradientLayer.endPoint=CGPointMake(1,1);
}
@end<img src="https://img-blog.csdn.net/20140521102444843" alt="" style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);" />
CAGradientLayer的属性设置
1类型
@property (copy) NSString *type
NSString *const kCAGradientLayerAxial 即线性梯度变化
2.颜色
@property(copy) NSArray *colors
3.位置参数
@property (copy) NSArray *locations
颜色的区间分布,location的数组长度要和colors一致,取值范围(0,1),而且必须是单调递增的
代码增加:
gradientLayer.locations=@[NSNumber numberWithFloat:0.0, NSNumber numberWithFloat:0.2];
4.startPoint和endPoint
@property CGPoint startPoint,endPoint;
取值都是相对于lay
er的bounds的,startPoint默认值为(0.5,0),endPoint默认值为(0.5,1)gradientLayer.startPoint 分别设为 CGPointMake(0, 0);
CGPointMake(0.25, 0);
CGPointMake(0.75,0)
CGPointMake(1,0)
startPoint和endPoint表示的渐变方向,location是渐变区域
http://blog.csdn.net/iunion/article/details/26221213