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

Content operation, do you know the strategies of these four important links?

This is an era of information overload. Even very...

Experts explain: What exactly is a “wetland”?

The 14th Conference of the Parties to the Convent...

This natural secret is called "the original appearance of the world"

Hello everyone, I am Chen Shiying, a nature conse...

The best 5-step user behavior path!

The market is becoming increasingly calm, and the...

Prepare for 618! The latest Baidu search & information flow advertising guide!

The biggest e-commerce promotion in the first hal...

Online event operation: How to make a "hot-selling micro-course"?

In this era of paid knowledge , whether you are a...