读书人

iOS应用开发课程:新建UIView的子类

发布时间: 2012-09-04 14:19:30 作者: rapoo

iOS应用开发教程:新建UIView的子类

From:?http://mobile.51cto.com/iphone-271839.htm

?

?

大致步骤

1) 新建一个UIView的子类(@interface HypnosisView : UIView)

2) 自定义绘图函数:(void) drawRect:(CGRect)rect

◆确定绘图范围:CGRect bounds=[self bounds]

◆获得CGContext, CGContextRef context=UIGraphicsGetCurrentContext();

◆进行绘图操作

3) 将新视图绑定到主窗口

◆在HypnosisterAppDelegate中添加一个成员变量HypnosisView *view;

◆确定绘图范围

◆在didFinishLaunchingWithOptions中增加子视图:[_window addSubview:view];

◆进行显示 [_window makeKeyAndVisible];

待确定事项:

1) CGContextStrokePath的功能

2) makeKeyAndVisible消息的功能

关键代码如下:

Java代码

1) 绑定处理:

  1. "didFinishLaunchingWithOptions.");??
  2. //?Override?point?for?customization?after?application?launch.??
  3. return?YES;??
  4. void)?drawRect:(CGRect)rect????
  5. "Entering?the?drawing?function?of?HyponsisView.");????
  6. //Get?the?drawing?rectangle????
  7. //Calculate?the?references????
  8. 2.0;????
  9. 2.0;????
  10. float?radius=hypot(bounds.size.width,?bounds.size.height)/2.0;????
  11. //Prepare?Drawing????
  12. 10);????
  13. //Drawing?the?circles????
  14. for(?float?r=radius;?r>0;?rr=r-25)????
  15. 0.0,?M_PI*2.0,YES);????
读书人网 >操作系统

热点推荐