您的位置:首页 > 移动开发 > IOS开发

ios绘制方法

2014-07-30 15:52 225 查看
在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];
}


我创建了一个QQ群,希望大家能本着互联网开放的心态,将遇到的问题和经验在群里分享,大家互相交流心得,共同提高。

群号:77311380
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: