iOS source code download: Implementing custom drawing functions

iOS source code download: Implementing custom drawing functions

Supported platforms: iOS

Operating environment: iOS

Development language: Object-C

Development tools: Xcode

Source code size: 166.12KB

Source code download address: http://down..com/data/1975550

Source code introduction

A customizable drawing function is implemented, which can dynamically select the pen color, line thickness, etc.

Source code running screenshot

Rendering

Source code snippet

  1. - (id)initWithFrame:(CGRect)frame afterToolColor:(ToolColorBlock)toolcolor
  2. {
  3. _toolColorBlock = toolcolor;
  4. self = [super initWithFrame:frame];
  5. if (self) {
  6. self.backgroundColor = [UIColor lightGrayColor];
  7. _colorArray = [NSArray array];
  8. NSArray *array = @[[UIColor darkGrayColor],
  9. [UIColor redColor],
  10. [UIColor greenColor],
  11. [UIColor blueColor],
  12. [UIColor yellowColor],
  13. [UIColor orangeColor],
  14. [UIColor purpleColor],
  15. [UIColor brownColor],
  16. [UIColor blackColor]];
  17.   
  18. _colorArray = array;
  19. [self creatColorButtons:array];
  20. }
  21. return self;
  22. }
  23.   
  24. - ( void )creatColorButtons:(NSArray *)array
  25. {
  26. NSInteger count = array.count;
  27. CGFloat buttonW = (self.bounds.size.width - (array.count+1)*kButtonSpace)/count;
  28. CGFloat buttonH = self.bounds.size.height;
  29. for (NSInteger i = 0; i<array.count; i++)= "" {= "" uicolor= "" *color= "array[i];" uibutton= "" *button= "[UIButton" buttonwithtype:uibuttontypecustom];= "" button.tag= "i;" [button= "" addtarget:self= "" action:@selector(tagbutton:)= "" forcontrolevents:uicontroleventtouchupinside];= "" cgfloat= "" buttonx= "kButtonSpace" += "" i= "" *= "" (buttonw= "" +kbuttonspace);= "" button.frame= "CGRectMake(buttonX," 5,= "" buttonw,= "" buttonh-10);= "" setbackgroundcolor:color];= "" [self= "" addsubview:button];= "" }= "" -= "" ( void )tagbutton:(uibutton= "" *)button= "" [uiview= "" animatewithduration:0.5f= "" animations:^{= "" self.frame= "CGRectMake(0," -self.bounds.size.height,= "" 320,= "" 44);= "" }];= "" _toolcolorblock(_colorarray[button.tag]);= "" }<= "" pre= "" >
  30.                       
  31. </array.count;>

Source code download address: http://down..com/data/1975550

<<:  iOS source code download: stacked cells in groups

>>:  European mobile game developers target the Chinese market, virtual reality becomes the future trend

Recommend

Analysis of Apple's Marketing Strategy

Since launching the industry-revolutionary iPhone...

3 tips to teach you how to write pain point copy!

Do you remember the heartwarming video of 999 Col...

How much does it cost to develop the Datong Jewelry Mini Program?

What is the price for developing Datong Jewelry M...

Credit card advertising and banking app user growth bottleneck

What are people competing for in the Internet cir...

Luxgen's new U6 SUV spy photos may be equipped with PSA engine

Recently, domestic media exposed a set of spy pho...

Who cut your budget?

A mistake that almost everyone tends to make: the...

How to build a B2B marketing omni-channel system?

Improving the conversion rate from leads to wins ...

Don’t be fooled by my short tail, I’m very powerful when hunting!

This is a kitten with eye-catching whiskers on it...

Apple's movie marketing strategy

Recently, Knives Out director Rian Johnson told V...

Alipay flashes digital RMB

The testing process of the digital RMB is acceler...