ios中绘制方法

在UIView的子类中,重写drawRect方法

画矩形

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetLineWidth(context, 5.0);
    
    CGContextSetStrokeColorWithColor(context, [[UIColor blueColor] CGColor]);
    //以此为起点
    CGContextMoveToPoint(context, rect.origin.x, rect.origin.y);
    //画四条线,以上一个点为起点,设置线终点
    CGContextAddLineToPoint(context, rect.size.width, rect.origin.y);
    CGContextAddLineToPoint(context, rect.size.width, rect.size.height);
    CGContextAddLineToPoint(context, rect.origin.x, rect.size.height);
    CGContextAddLineToPoint(context, rect.origin.x, rect.origin.y);
    
    CGContextStrokePath(context);
}

画文字

- (void)drawRect:(CGRect)rect
{
    //画文字
    UIFont *font = [UIFont systemFontOfSize:8];
    //在指定x,y点位置画文字,宽度为18
    NSString* str = @"在指定x,y点位置画文字,宽度为18";
    [str drawAtPoint:CGPointMake(20, 20) withAttributes:@{NSFontAttributeName: font,NSForegroundColorAttributeName:[UIColor redColor]}];
}

UIView动画

-(void)animationImageView
{
    UIImageView* animationImageView = [[UIImageView alloc] initWithFrame:self.view.frame];
    animationImageView.animationImages = @[[UIImage imageNamed:@"loading-1.png"],[UIImage imageNamed:@"loading-2.png"],[UIImage imageNamed:@"loading-3.png"],[UIImage imageNamed:@"loading-4.png"]];
  
// imageFrames 是一个图片数组   animationImageView是一个imageview
//    [UIView setAnimationDelegate:self];
    animationImageView.animationDuration = 0.75f;
    animationImageView.animationRepeatCount = 0;
    [animationImageView startAnimating];
    [self.view addSubview:animationImageView];
}

你可能感兴趣的:(ios中绘制方法)