iOS源碼下載:實現自定義畫圖功能
作者:佚名
實現了可自定義的畫圖功能,可以動態選擇圖筆的顏色,線條粗細等。
支持平臺:iOS
運行環境:iOS
開發語言:Object-c
開發工具:Xcode
源碼大?。?66.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;>
責任編輯:閆佳明
來源:
網絡整理