如何绘制一个只是一个圆圈的自定义UIView - iPhone应用程序 [英] How to draw a custom UIView that is just a circle - iPhone app

查看:132
本文介绍了如何绘制一个只是一个圆圈的自定义UIView - iPhone应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何绘制一个自定义的UIView,它实际上只是一个球(2D圆圈)?我会覆盖drawRect方法吗?有人能告诉我绘制蓝色圆圈的代码吗?

How would I go about drawing a custom UIView that is literally just a ball (a 2D circle)? Would I just override the drawRect method? And can someone show me the code for drawing a blue circle?

此外,是否可以在班级内更改该视图的框架?或者我是否需要从不同的班级更改框架?

Also, would it be okay to change the frame of that view within the class itself? Or do I need to change the frame from a different class?

(只是试图设置一个球弹跳)

(just trying to set up a ball bouncing around)

推荐答案

您可以使用QuartzCore并执行此操作 -

You could use QuartzCore and do something this --

self.circleView = [[UIView alloc] initWithFrame:CGRectMake(10,20,100,100)];
self.circleView.alpha = 0.5;
self.circleView.layer.cornerRadius = 50;  // half the width/height
self.circleView.backgroundColor = [UIColor blueColor];

这篇关于如何绘制一个只是一个圆圈的自定义UIView - iPhone应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆