Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some refactoring #65

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions Demo/XYPieChart.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
87FEAA0E14F84E3000ED38A2 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0420;
LastUpgradeCheck = 0630;
ORGANIZATIONNAME = "Xiaoyang Feng";
};
buildConfigurationList = 87FEAA1114F84E3000ED38A2 /* Build configuration list for PBXProject "XYPieChart" */;
Expand Down Expand Up @@ -207,24 +207,37 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
ONLY_ACTIVE_ARCH = YES;
PROVISIONING_PROFILE = "";
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = 2;
Expand All @@ -235,14 +248,26 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
COPY_PHASE_STRIP = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
Expand Down
27 changes: 8 additions & 19 deletions Demo/XYPieChart/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ @implementation ViewController
@synthesize slices = _slices;
@synthesize sliceColors = _sliceColors;

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
Expand Down Expand Up @@ -82,11 +76,6 @@ - (void)viewDidUnload
[super viewDidUnload];
}

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
Expand Down Expand Up @@ -119,7 +108,7 @@ - (IBAction)SliceNumChanged:(id)sender
if(btn.tag == 101 && num < 10)
num = num + ((num == -1)?2:1);

self.numOfSlices.text = [NSString stringWithFormat:@"%d",num];
self.numOfSlices.text = [NSString stringWithFormat:@"%ld",(long)num];
}

- (IBAction)clearSlices {
Expand All @@ -130,9 +119,9 @@ - (IBAction)clearSlices {

- (IBAction)addSliceBtnClicked:(id)sender
{
NSInteger num = [self.numOfSlices.text intValue];
int num = [self.numOfSlices.text intValue];
if (num > 0) {
for (int n=0; n < abs(num); n++)
for (int n=0; n < abs(num); n++)
{
NSNumber *one = [NSNumber numberWithInt:rand()%60+20];
NSInteger index = 0;
Expand All @@ -153,7 +142,7 @@ - (IBAction)addSliceBtnClicked:(id)sender
else if (num < 0)
{
if(self.slices.count <= 0) return;
for (int n=0; n < abs(num); n++)
for (int n=0; n < abs(num); n++)
{
NSInteger index = 0;
if(self.slices.count > 0)
Expand Down Expand Up @@ -210,19 +199,19 @@ - (UIColor *)pieChart:(XYPieChart *)pieChart colorForSliceAtIndex:(NSUInteger)in
#pragma mark - XYPieChart Delegate
- (void)pieChart:(XYPieChart *)pieChart willSelectSliceAtIndex:(NSUInteger)index
{
NSLog(@"will select slice at index %d",index);
NSLog(@"will select slice at index %lu",(unsigned long)index);
}
- (void)pieChart:(XYPieChart *)pieChart willDeselectSliceAtIndex:(NSUInteger)index
{
NSLog(@"will deselect slice at index %d",index);
NSLog(@"will deselect slice at index %lu",(unsigned long)index);
}
- (void)pieChart:(XYPieChart *)pieChart didDeselectSliceAtIndex:(NSUInteger)index
{
NSLog(@"did deselect slice at index %d",index);
NSLog(@"did deselect slice at index %lu",(unsigned long)index);
}
- (void)pieChart:(XYPieChart *)pieChart didSelectSliceAtIndex:(NSUInteger)index
{
NSLog(@"did select slice at index %d",index);
NSLog(@"did select slice at index %lu",(unsigned long)index);
self.selectedSliceLabel.text = [NSString stringWithFormat:@"$%@",[self.slices objectAtIndex:index]];
}

Expand Down
6 changes: 3 additions & 3 deletions XYPieChart/XYPieChart.m
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ - (void)setShowPercentage:(BOOL)showPercentage
label = [NSString stringWithFormat:@"%0.0f", layer.percentage*100];
else
label = (layer.text)?layer.text:[NSString stringWithFormat:@"%0.0f", layer.value];
CGSize size = [label sizeWithFont:self.labelFont];
CGSize size = [label sizeWithAttributes:@{NSFontAttributeName : self.labelFont}];

if(M_PI*2*_labelRadius*layer.percentage < MAX(size.width,size.height))
{
Expand Down Expand Up @@ -640,7 +640,7 @@ - (SliceLayer *)createSliceLayer
[textLayer setShadowOpacity:1.0f];
[textLayer setShadowRadius:2.0f];
}
CGSize size = [@"0" sizeWithFont:self.labelFont];
CGSize size = [@"0" sizeWithAttributes:@{NSFontAttributeName : self.labelFont}];
[CATransaction setDisableActions:YES];
[textLayer setFrame:CGRectMake(0, 0, size.width, size.height)];
[textLayer setPosition:CGPointMake(_pieCenter.x + (_labelRadius * cos(0)), _pieCenter.y + (_labelRadius * sin(0)))];
Expand All @@ -660,7 +660,7 @@ - (void)updateLabelForLayer:(SliceLayer *)pieLayer value:(CGFloat)value
else
label = (pieLayer.text)?pieLayer.text:[NSString stringWithFormat:@"%0.0f", value];

CGSize size = [label sizeWithFont:self.labelFont];
CGSize size = [label sizeWithAttributes:@{NSFontAttributeName : self.labelFont}];

[CATransaction setDisableActions:YES];
if(M_PI*2*_labelRadius*pieLayer.percentage < MAX(size.width,size.height) || value <= 0)
Expand Down