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

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

问题描述

我将如何绘制一个实际上只是一个球(一个 2D 圆)的自定义 UIView?我会覆盖 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天全站免登陆