Skip to content

Commit

Permalink
Merge pull request #6 from evan3rd/master
Browse files Browse the repository at this point in the history
fix UIControlState warning
  • Loading branch information
rizumita committed Jun 16, 2015
2 parents fc60c15 + 3f7799b commit 03cb4ab
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 25 deletions.
6 changes: 4 additions & 2 deletions CTCheckbox.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
};
Expand All @@ -324,7 +324,7 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
};
Expand Down Expand Up @@ -398,6 +398,7 @@
6A99A79116E6DB8000F173B2 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
6A99A7B416E6DBA000F173B2 /* Build configuration list for PBXNativeTarget "CTCheckboxSample" */ = {
isa = XCConfigurationList;
Expand All @@ -406,6 +407,7 @@
6A99A7B616E6DBA000F173B2 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
68 changes: 45 additions & 23 deletions CTCheckbox/CTCheckbox.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,20 @@ - (void)changeColorForState:(UIControlState)state
{
UIColor *color;

if (state & UIControlStateNormal) {
switch (state) {
case UIControlStateNormal:
color = self.colorDictionary[@(UIControlStateNormal)];
} else if (state & UIControlStateSelected) {
break;
case UIControlStateSelected:
color = self.colorDictionary[@(UIControlStateSelected)];
} else if (state & UIControlStateDisabled) {
break;
case UIControlStateDisabled:
color = self.colorDictionary[@(UIControlStateDisabled)];
break;
default:
break;
}

if (!color) {
color = [UIColor blackColor];
}
Expand All @@ -94,14 +100,20 @@ - (void)changeBackgroundColorForState:(UIControlState)state
{
UIColor *color;

if (state & UIControlStateNormal) {
switch (state) {
case UIControlStateNormal:
color = self.backgroundColorDictionary[@(UIControlStateNormal)];
} else if (state & UIControlStateSelected) {
break;
case UIControlStateSelected:
color = self.backgroundColorDictionary[@(UIControlStateSelected)];
} else if (state & UIControlStateDisabled) {
break;
case UIControlStateDisabled:
color = self.backgroundColorDictionary[@(UIControlStateDisabled)];
break;
default:
break;
}

if (!color) {
color = [UIColor clearColor];
}
Expand All @@ -127,27 +139,40 @@ - (void)setCheckboxColor:(UIColor *)checkboxColor

- (void)setColor:(UIColor *)color forControlState:(UIControlState)state
{
if (state & UIControlStateNormal) {
switch (state) {
case UIControlStateNormal:
self.colorDictionary[@(UIControlStateNormal)] = color;
} else if (state & UIControlStateSelected) {
break;
case UIControlStateSelected:
self.colorDictionary[@(UIControlStateSelected)] = color;
} else if (state & UIControlStateDisabled) {
break;
case UIControlStateDisabled:
self.colorDictionary[@(UIControlStateDisabled)] = color;
break;
default:
break;
}

[self changeColorForState:self.state];
}

- (void)setBackgroundColor:(UIColor *)backgroundColor forControlState:(UIControlState)state
{
if (state & UIControlStateNormal) {
switch (state) {
case UIControlStateNormal:
self.backgroundColorDictionary[@(UIControlStateNormal)] = backgroundColor;
} else if (state & UIControlStateSelected) {
break;
case UIControlStateSelected:
self.backgroundColorDictionary[@(UIControlStateSelected)] = backgroundColor;
} else if (state & UIControlStateDisabled) {
break;
case UIControlStateDisabled:
self.backgroundColorDictionary[@(UIControlStateDisabled)] = backgroundColor;
break;
default:
break;
}



[self changeBackgroundColorForState:self.state];
}

Expand Down Expand Up @@ -184,13 +209,10 @@ - (void)layoutSubviews
CGFloat textLabelOriginX = self.checkboxSideLength + 5.0;
CGSize textLabelMaxSize = CGSizeMake(CGRectGetWidth(self.bounds) - textLabelOriginX, CGRectGetHeight(self.bounds));

CGSize textLabelSize;
if ([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending) {
textLabelSize = [self.textLabel.text sizeWithAttributes:@{NSFontAttributeName : self.textLabel.font}];
} else {
textLabelSize = [self.textLabel.text sizeWithFont:self.textLabel.font constrainedToSize:textLabelMaxSize lineBreakMode:self.textLabel.lineBreakMode];
}

CGRect r = [self.textLabel.text boundingRectWithSize:textLabelMaxSize options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) attributes:@{NSFontAttributeName:self.textLabel.font} context:nil];

CGSize textLabelSize = CGSizeMake(r.size.width, r.size.height);

self.textLabel.frame = CGRectIntegral(CGRectMake(textLabelOriginX, (CGRectGetHeight(self.bounds) - textLabelSize.height) / 2.0, textLabelSize.width, textLabelSize.height));
}

Expand Down

0 comments on commit 03cb4ab

Please sign in to comment.