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

After using iOS 15, I am sure Apple has no solution

After looking forward to it for a long time, Appl...

Does breathing affect vision? Scientists discover mysterious rules of pupils →

Compiled by: Gong Zixin Like the aperture of a ca...

This year's Qixi marketing, big brands are doing it this way

It’s Chinese Valentine’s Day again! ! ! Such dog-...

Will the Apple Watch be a hit?

[[129121]] Here it comes, the Apple Watch is fina...

Will cement batteries be the next energy revolution?

Written by Wang Yuesheng (PhD in Condensed Matter...

The most practical seed user operation method

I have been wanting to talk about the seed user o...

Hupu product analysis report!

On June 6, 2019, Hupu Sports Community received a...

Why does Nokia dare to sell its new Android 7.0 phone for 1,699 yuan?

Nokia was once the undisputed king of the mobile ...