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

Chen Changwen's method: Confessions of a community member

Every perceptive entrepreneur should practice soc...

Acquiring users: 5 common fission methods

As the cost of acquiring traffic becomes higher a...

Monkeypox Science | The "monkey" in monkeypox is not the "monkey" in monkey

On June 24, Taiwan’s Centers for Disease Control ...

Title tips to get 100,000+ clicks on public account articles!

Want your public account articles to get 100,000+...

What? Krill are not shrimp?

Antarctic krill (scientific name: Euphausia super...

Highlights of APP free and paid channel promotion!

Before I did it, I had heard of various methods o...