Chapter 5 帶顏色的同心圓

來源:互聯網
上載者:User

標籤:style   blog   color   io   ar   for   div   art   sp   

一、重寫 DrwaRect

-(void)drawRect:(CGRect)rect{    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 = MAX(bounds.size.width, bounds.size.height);    
  // 畫圓 UIBezierPath *path = [[UIBezierPath alloc] init]; for(float currentRadius = maxRadius; currentRadius > 0; currentRadius -= 20) { [path moveToPoint:CGPointMake(center.x + currentRadius, center.y)]; [path addArcWithCenter:center radius:currentRadius startAngle:0.0 endAngle:M_PI * 2.0 clockwise:YES]; } path.lineWidth = 10; // Configure the drawing color of light gray [self.circleColor setStroke]; [path stroke]; /* CGContextRef currentContext = UIGraphicsGetCurrentContext(); CGContextSaveGState(currentContext); [path addClip]; // Gradient triangle CGFloat location[2] = {0.0, 1.0}; CGFloat components[8] = {1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0}; CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB(); CGGradientRef gradient = CGGradientCreateWithColorComponents(colorspace, components, location, 2); CGPoint startPoint = CGPointMake(rect.size.width / 2.0, rect.size.height / 4.0); CGPoint endPoint = CGPointMake(rect.size.width / 2.0 , rect.size.height * 0.75); CGContextDrawLinearGradient(currentContext, gradient, startPoint, endPoint, 0); CGColorSpaceRelease(colorspace); CGGradientRelease(gradient); // Add shadow of image CGContextSetShadow(currentContext, CGSizeMake(4.0, 7.0), 3); // Draw stuff here, it will appear with a shadow // Add logo image UIImage *logoImage = [UIImage imageNamed:@"logo.png"]; CGRect logoRect = CGRectMake(rect.size.width / 4.0, rect.size.height / 4.0, rect.size.width/2.0, rect.size.height / 2.0); [logoImage drawInRect:logoRect]; CGContextRestoreGState(currentContext); // Draw stuff here, it will apear with no shadow; CGContextRelease(currentContext); */}

二、重寫 touchesBegin:withEvent 

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{//    NSLog(@"%@ was touched", self);        // Get 3 random numbers between 0 and 1    float red = (arc4random() % 100) / 100.0;    float blue = (arc4random() % 100) / 100.0;    float green = (arc4random() % 100) / 100.0;        UIColor *randomColor = [UIColor colorWithRed:red green:green blue:blue alpha:1.0];    self.circleColor = randomColor;}

三、重繪 View

[self setNeedsDisplay];

 

Chapter 5 帶顏色的同心圓

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.