支持平台:iOS
运行环境:iOS
开发语言:Object-c
开发工具:Xcode
源码大小:166.12KB
源码下载地址:http://down.51cto.com/data/1975550
源码简介
实现了可自定义的画图功能,可以动态选择图笔的颜色,线条粗细等。
源码运行截图
效果图
源码片段
- - (id)initWithFrame:(CGRect)frame afterToolColor:(ToolColorBlock)toolcolor
- {
- _toolColorBlock = toolcolor;
- self = [super initWithFrame:frame];
- if (self) {
- self.backgroundColor = [UIColor lightGrayColor];
- _colorArray = [NSArray array];
- NSArray *array = @[[UIColor darkGrayColor],
- [UIColor redColor],
- [UIColor greenColor],
- [UIColor blueColor],
- [UIColor yellowColor],
- [UIColor orangeColor],
- [UIColor purpleColor],
- [UIColor brownColor],
- [UIColor blackColor]];
- _colorArray = array;
- [self creatColorButtons:array];
- }
- return self;
- }
- - (void)creatColorButtons:(NSArray *)array
- {
- NSInteger count = array.count;
- CGFloat buttonW = (self.bounds.size.width - (array.count+1)*kButtonSpace)/count;
- CGFloat buttonH = self.bounds.size.height;
- 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="">
- </array.count;>