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

How to create a WeChat mini program store?

Since the launch of the WeChat Mini Program websi...

Marketing strategies for taking advantage of the Mid-Autumn Festival!

The Mid-Autumn Festival is approaching, and major...

How can marketers help startup brands write a complete set of brand copy?

In August 2019, I took on a project in which I tr...

How to make the African kids' happy birthday video?

Today, editor Feng Chao will explain to you how t...

Complete the entire calculus course in 19 hours

Course Description The Calculus video tutorial co...

Baidu should not rush into making driverless cars

Recently, at the China Cloud Computing Conference...

Five key directions for new media professionals in 2019

WeChat has quietly revamped its version recently!...