From f8191922ef086e714119335c5685cd3b3e3c4131 Mon Sep 17 00:00:00 2001 From: wujunyang Date: Sat, 20 May 2017 13:44:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=85=B3=E4=BA=8E=E6=9F=B1?= =?UTF-8?q?=E7=8A=B6=20=E9=A5=BC=E5=9B=BE=E7=9A=84=E5=AE=9E=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MobileProject.xcodeproj/project.pbxproj | 16 +++++ .../xcdebugger/Breakpoints_v2.xcbkptlist | 12 ---- .../Controller/MPMasonryViewController.m | 2 +- .../Controller/MPUIBezierPathViewController.m | 13 +++++ .../Main/Theory/View/MPBarChartView.h | 13 +++++ .../Main/Theory/View/MPBarChartView.m | 54 +++++++++++++++++ .../Main/Theory/View/MPPieChartView.h | 13 +++++ .../Main/Theory/View/MPPieChartView.m | 58 +++++++++++++++++++ 8 files changed, 168 insertions(+), 13 deletions(-) create mode 100644 MobileProject/Main/Theory/View/MPBarChartView.h create mode 100644 MobileProject/Main/Theory/View/MPBarChartView.m create mode 100644 MobileProject/Main/Theory/View/MPPieChartView.h create mode 100644 MobileProject/Main/Theory/View/MPPieChartView.m diff --git a/MobileProject.xcodeproj/project.pbxproj b/MobileProject.xcodeproj/project.pbxproj index 45fb188..25b6240 100644 --- a/MobileProject.xcodeproj/project.pbxproj +++ b/MobileProject.xcodeproj/project.pbxproj @@ -338,6 +338,10 @@ 34B8DB001E82A5ED009649A5 /* MPModelBlockViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B8DAFE1E82A5ED009649A5 /* MPModelBlockViewController.m */; }; 34C089681EC1AAAF004A6B03 /* MPVideoClipViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34C089671EC1AAAF004A6B03 /* MPVideoClipViewController.m */; }; 34C089691EC1AAAF004A6B03 /* MPVideoClipViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34C089671EC1AAAF004A6B03 /* MPVideoClipViewController.m */; }; + 34D5A1771ECE8B4E0093FAE0 /* MPBarChartView.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D5A1761ECE8B4E0093FAE0 /* MPBarChartView.m */; }; + 34D5A1781ECE8B4E0093FAE0 /* MPBarChartView.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D5A1761ECE8B4E0093FAE0 /* MPBarChartView.m */; }; + 34D5A17B1ECE8FD70093FAE0 /* MPPieChartView.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D5A17A1ECE8FD60093FAE0 /* MPPieChartView.m */; }; + 34D5A17C1ECE8FD70093FAE0 /* MPPieChartView.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D5A17A1ECE8FD60093FAE0 /* MPPieChartView.m */; }; 34E08A551C3BE80F005C6CA3 /* GVUserDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 34E08A541C3BE80F005C6CA3 /* GVUserDefaults.m */; }; 34E08A591C3BEA89005C6CA3 /* GVUserDefaults+BBProperties.m in Sources */ = {isa = PBXBuildFile; fileRef = 34E08A581C3BEA89005C6CA3 /* GVUserDefaults+BBProperties.m */; }; 34E08A5D1C3BEEF2005C6CA3 /* MyFileLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = 34E08A5C1C3BEEF2005C6CA3 /* MyFileLogger.m */; }; @@ -1337,6 +1341,10 @@ 34B8DAFE1E82A5ED009649A5 /* MPModelBlockViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPModelBlockViewController.m; sourceTree = ""; }; 34C089661EC1AAAF004A6B03 /* MPVideoClipViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPVideoClipViewController.h; sourceTree = ""; }; 34C089671EC1AAAF004A6B03 /* MPVideoClipViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPVideoClipViewController.m; sourceTree = ""; }; + 34D5A1751ECE8B4E0093FAE0 /* MPBarChartView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPBarChartView.h; sourceTree = ""; }; + 34D5A1761ECE8B4E0093FAE0 /* MPBarChartView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPBarChartView.m; sourceTree = ""; }; + 34D5A1791ECE8FD60093FAE0 /* MPPieChartView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPPieChartView.h; sourceTree = ""; }; + 34D5A17A1ECE8FD60093FAE0 /* MPPieChartView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPPieChartView.m; sourceTree = ""; }; 34E08A531C3BE80F005C6CA3 /* GVUserDefaults.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GVUserDefaults.h; sourceTree = ""; }; 34E08A541C3BE80F005C6CA3 /* GVUserDefaults.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GVUserDefaults.m; sourceTree = ""; }; 34E08A571C3BEA89005C6CA3 /* GVUserDefaults+BBProperties.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GVUserDefaults+BBProperties.h"; sourceTree = ""; }; @@ -2542,6 +2550,10 @@ 34FB62C21E8DFFBC0036AA3D /* MPPhotoCell+ConfigureForPhoto.m */, 340793831EA9A49400AF184A /* MPContextView.h */, 340793841EA9A49400AF184A /* MPContextView.m */, + 34D5A1751ECE8B4E0093FAE0 /* MPBarChartView.h */, + 34D5A1761ECE8B4E0093FAE0 /* MPBarChartView.m */, + 34D5A1791ECE8FD60093FAE0 /* MPPieChartView.h */, + 34D5A17A1ECE8FD60093FAE0 /* MPPieChartView.m */, ); path = View; sourceTree = ""; @@ -5349,11 +5361,13 @@ 34E08B3C1C3BFB90005C6CA3 /* NSNumber+CGFloat.m in Sources */, 34FA475F1D50961600D5B729 /* MPChildrenViewController.m in Sources */, 34FE0B921D50FF7C00991E65 /* MPHideNavigationViewController.m in Sources */, + 34D5A1781ECE8B4E0093FAE0 /* MPBarChartView.m in Sources */, 34E08B3F1C3BFB90005C6CA3 /* NSString+Ruby.m in Sources */, 34E08B401C3BFB90005C6CA3 /* UISplitViewController+QuickAccess.m in Sources */, 34F72FD91E8C95FF002B0709 /* YTKChainRequest.m in Sources */, 34E08B421C3BFB90005C6CA3 /* NSURL+QueryDictionary.m in Sources */, 3400E4C41D35EEF00056B673 /* MPLKDBHelper.m in Sources */, + 34D5A17C1ECE8FD70093FAE0 /* MPPieChartView.m in Sources */, 34E08B431C3BFB90005C6CA3 /* MJRefreshBackStateFooter.m in Sources */, 34E08B441C3BFB90005C6CA3 /* NSPersistentStoreCoordinator+Custom.m in Sources */, 34799A641CD34C5A003518C5 /* UIDevice+FCUUID.m in Sources */, @@ -5733,6 +5747,7 @@ 34E893A41C3B9A03001327C8 /* NSString+Encrypt.m in Sources */, 3411EF101D6FEC1A00A6C7F3 /* CanvasView.m in Sources */, 34E893A61C3B9A03001327C8 /* NSString+Matcher.m in Sources */, + 34D5A1771ECE8B4E0093FAE0 /* MPBarChartView.m in Sources */, 34F72FD31E8C95E9002B0709 /* YTKNetworkConfig.m in Sources */, 340C853D1E724BCF00B59C2E /* MPProtocolOptionalViewController.m in Sources */, 34E894111C3B9A03001327C8 /* UITableView+iOS7Style.m in Sources */, @@ -5823,6 +5838,7 @@ 340793811EA9A3BE00AF184A /* MPCGContextViewController.m in Sources */, 34E894101C3B9A03001327C8 /* UISplitViewController+QuickAccess.m in Sources */, 340D87991D3F6310003D9C88 /* dateTimeHelper.m in Sources */, + 34D5A17B1ECE8FD70093FAE0 /* MPPieChartView.m in Sources */, 34E893B51C3B9A03001327C8 /* NSURL+QueryDictionary.m in Sources */, 34E891211C3B92AA001327C8 /* MJRefreshBackStateFooter.m in Sources */, 34E893691C3B9A03001327C8 /* NSPersistentStoreCoordinator+Custom.m in Sources */, diff --git a/MobileProject.xcworkspace/xcuserdata/wujunyang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/MobileProject.xcworkspace/xcuserdata/wujunyang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index e2573a5..ed9a9b4 100644 --- a/MobileProject.xcworkspace/xcuserdata/wujunyang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/MobileProject.xcworkspace/xcuserdata/wujunyang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -2,16 +2,4 @@ - - - - - - diff --git a/MobileProject/Main/Preview/Controller/MPMasonryViewController.m b/MobileProject/Main/Preview/Controller/MPMasonryViewController.m index 6a0cbcb..09a044e 100644 --- a/MobileProject/Main/Preview/Controller/MPMasonryViewController.m +++ b/MobileProject/Main/Preview/Controller/MPMasonryViewController.m @@ -24,6 +24,7 @@ - (void)viewDidLoad { [self masonryLabelHeightLayout]; [self masonryPriorityLayout]; + [self masonryPriorityOtherLayout]; [self masonryEdgesCenterLayout]; @@ -31,7 +32,6 @@ - (void)viewDidLoad { [self masonryScrollViewLayout]; [self masonryUpdateLayout]; - } - (void)didReceiveMemoryWarning { diff --git a/MobileProject/Main/Theory/Controller/MPUIBezierPathViewController.m b/MobileProject/Main/Theory/Controller/MPUIBezierPathViewController.m index 2f261b7..bc8011b 100644 --- a/MobileProject/Main/Theory/Controller/MPUIBezierPathViewController.m +++ b/MobileProject/Main/Theory/Controller/MPUIBezierPathViewController.m @@ -7,6 +7,8 @@ // #import "MPUIBezierPathViewController.h" +#import "MPBarChartView.h" +#import "MPPieChartView.h" @interface MPUIBezierPathViewController () { @@ -43,6 +45,17 @@ - (void)viewDidLoad { [self Bubble]; [self circleAnimation]; + + + //画柱状图 + MPBarChartView *barChartView=[[MPBarChartView alloc]initWithFrame:CGRectMake(20, 440, 200, 150)]; + barChartView.backgroundColor=[UIColor grayColor]; + [self.view addSubview:barChartView]; + + //画饼图 + MPPieChartView *pieChartView=[[MPPieChartView alloc]initWithFrame:CGRectMake(230, 350, 150, 150)]; + pieChartView.backgroundColor=[UIColor whiteColor]; + [self.view addSubview:pieChartView]; } diff --git a/MobileProject/Main/Theory/View/MPBarChartView.h b/MobileProject/Main/Theory/View/MPBarChartView.h new file mode 100644 index 0000000..b168294 --- /dev/null +++ b/MobileProject/Main/Theory/View/MPBarChartView.h @@ -0,0 +1,13 @@ +// +// MPBarChartView.h +// MobileProject +// +// Created by wujunyang on 2017/5/19. +// Copyright © 2017年 wujunyang. All rights reserved. +// + +#import + +@interface MPBarChartView : UIView + +@end diff --git a/MobileProject/Main/Theory/View/MPBarChartView.m b/MobileProject/Main/Theory/View/MPBarChartView.m new file mode 100644 index 0000000..f6a4481 --- /dev/null +++ b/MobileProject/Main/Theory/View/MPBarChartView.m @@ -0,0 +1,54 @@ +// +// MPBarChartView.m +// MobileProject +// +// Created by wujunyang on 2017/5/19. +// Copyright © 2017年 wujunyang. All rights reserved. +// + +#import "MPBarChartView.h" + +#define BAR_HEIGHT_COEFFICIENT 0.9 + +@implementation MPBarChartView + +- (void)drawRect:(CGRect)rect{ + NSArray *arry = @[@300,@232.233,@324.324,@34,@435,@43.0]; + + // 计算bar的宽度 + CGFloat barW = self.bounds.size.width / (arry.count * 2 - 1); + + // 找出数组中的最大数值 + CGFloat maxValue = [[arry valueForKeyPath:@"@max.floatValue"] floatValue]; + + for (NSInteger i = 0; i < arry.count; i++) { + // 计算bar的高度 + CGFloat barH = [arry[i] floatValue] * (self.bounds.size.height * BAR_HEIGHT_COEFFICIENT/ maxValue); + + // 计算bar的XY + CGFloat barX = barW * i * 2; + CGFloat barY = self.bounds.size.height - barH; + + // 绘制矩形 + UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(barX, barY, barW, barH)]; + + // 给矩形添加随机色 + [[self randomUIColor] set]; + + [path fill]; + + + } +} + +- (UIColor *)randomUIColor{ + UIColor *color = [UIColor colorWithRed:(arc4random_uniform(256) / 255.0) green:(arc4random_uniform(256) / 255.0) blue:(arc4random_uniform(256) / 255.0) alpha:(arc4random_uniform(256) / 255.0)]; + return color; +} + +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ + + [self setNeedsDisplay]; +} + +@end diff --git a/MobileProject/Main/Theory/View/MPPieChartView.h b/MobileProject/Main/Theory/View/MPPieChartView.h new file mode 100644 index 0000000..43c5d51 --- /dev/null +++ b/MobileProject/Main/Theory/View/MPPieChartView.h @@ -0,0 +1,13 @@ +// +// MPPieChartView.h +// MobileProject +// +// Created by wujunyang on 2017/5/19. +// Copyright © 2017年 wujunyang. All rights reserved. +// + +#import + +@interface MPPieChartView : UIView + +@end diff --git a/MobileProject/Main/Theory/View/MPPieChartView.m b/MobileProject/Main/Theory/View/MPPieChartView.m new file mode 100644 index 0000000..09330ba --- /dev/null +++ b/MobileProject/Main/Theory/View/MPPieChartView.m @@ -0,0 +1,58 @@ +// +// MPPieChartView.m +// MobileProject +// +// Created by wujunyang on 2017/5/19. +// Copyright © 2017年 wujunyang. All rights reserved. +// + +#import "MPPieChartView.h" + +@implementation MPPieChartView + +- (void)drawRect:(CGRect)rect { + // Drawing code + + NSArray *arry = @[@300,@232.233,@324.324,@34,@4352,@43.0]; + + // 计算数组中所有数值之和 + CGFloat sumValue = [[arry valueForKeyPath:@"@sum.floatValue"] floatValue]; + + //设定圆弧的圆点、起始弧度 + CGPoint origin = CGPointMake(80, 80); + CGFloat startAngle = 0; + CGFloat endAngle = 0; + + + for (NSInteger i = 0 ; i < arry.count; i++) { + + // 每个数据的弧度 + CGFloat angle = [arry[i] floatValue] * M_PI * 2 / sumValue; + + // 计算这一段弧度的结束为止 + endAngle = startAngle + angle; + + UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:origin radius:40 startAngle:startAngle endAngle:endAngle clockwise:YES]; + + // 计算下一段弧度开始的位置 + startAngle = endAngle; + + // 从弧边,绘制到原点。用于封闭路径,可以绘制扇形 + [path addLineToPoint:origin]; + // 给扇形添加随机色 + [[self randomUIColor] set]; + [path fill]; + } + +} + +- (UIColor *)randomUIColor{ + UIColor *color = [UIColor colorWithRed:(arc4random_uniform(256) / 255.0) green:(arc4random_uniform(256) / 255.0) blue:(arc4random_uniform(256) / 255.0) alpha:(arc4random_uniform(256) / 255.0)]; + return color; +} +//触屏后重新渲染 +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ + [self setNeedsDisplay]; +} + +@end