IOS 类方法

1.新建一个类 继承自UIView

重写UIView 里面的方法

    CGRect bounds=[self bounds];
   
CGPoint center;
   
center.x=bounds.origin.x+bounds.size.width/2.0;
 
   center.y=bounds.origin.y+bounds.size.height/2.0;
 
   float maxRadius=hypot(bounds.size.width, bounds.size.height)/2.0;
 
   CGContextRef content=UIGraphicsGetCurrentContext();
   

    CGContextSetLineWidth(content, 10);
  
  [[UIColor lightGrayColor]setStroke];
   
for(float currentRadis=maxRadius;currentRadis>0;currentRadis-=20)
   
{
    
   
       
CGContextAddArc(content, center.x, center.y, currentRadis, 0.0, M_PI*2.0, YES);
   
     CGContextStrokePath(content);
   
}
   
  
  NSString *text=[[NSString alloc]initWithString:@"bin ge wei wu"];
  
  UIFont  *font=[UIFont boldSystemFontOfSize:28];
   

    CGRect textRect;
    textRect.size=[text sizeWithFont:font];
   
textRect.origin.x=center.x-textRect.size.width/2.0;
 
   textRect.origin.y=center.y-textRect.size.height/2.0;
  
  [[UIColor blackColor]setFill];
   
CGSize offset=CGSizeMake(4, 3);
  
  CGColorRef color=[[UIColor darkGrayColor]CGColor];
 
  CGContextSetShadowWithColor(content, offset, 2.0,color);
  
  [text drawInRect:textRect withFont:font];
   

在.m文件里面使用

    UIView *backview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
    CGRect wholewindwos=[backview bounds];
    view=[[hypnosisview alloc]initWithFrame:wholewindwos];
  
    [ backview addSubview:view];
    
    [self.view addSubview:backview];

 

 

posted @ 2012-10-17 10:13  銱ル╬鎯噹  阅读(288)  评论(0编辑  收藏  举报