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中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥ios动画全貌。在这里你可以看...
    每天刷两次牙阅读 12,711评论 6 30
  • 目录: 主要绘图框架介绍 CALayer 绘图 贝塞尔曲线-UIBezierPath CALayer子类 补充:i...
    Ryan___阅读 5,635评论 1 9
  • Core Graphics Framework是一套基于C的API框架,使用了Quartz作为绘图引擎。它提供了低...
    ShanJiJi阅读 5,535评论 0 20
  • 接上篇 传言,魔灵也许和人类有某些联系,从上一篇出土一些图片信息看,他们跟人类长得很像,或许和人类有过交集,或许他...
    我是KiShua阅读 2,507评论 3 4
  • 最近被各公众号的《我的前半生》各种刷屏,有的说这个剧讲了女主如何逆袭,有的说讲了小三如何上位,更多的人说讲了女人当...
    zxj_df20阅读 2,924评论 0 3