Skip to content

Commit

Permalink
Change design
Browse files Browse the repository at this point in the history
  • Loading branch information
rizumita committed Dec 25, 2013
1 parent 5e03e37 commit 0c4e7a1
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 82 deletions.
51 changes: 20 additions & 31 deletions CTCheckbox/CTCheckbox.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#import "CTCheckbox.h"

static const float CTCheckboxDefaultSideLength = 20.0;

@implementation CTCheckbox

- (id)initWithFrame:(CGRect)frame
Expand All @@ -30,10 +32,11 @@ - (id)initWithCoder:(NSCoder *)aDecoder

- (void)setUp
{
self.checkboxSideLength = 20.0;
self.checkboxSideLength = CTCheckboxDefaultSideLength;
self.checkboxColor = [UIColor blackColor];
self.backgroundColor = [UIColor clearColor];
self.textLabel = [[UILabel alloc] initWithFrame:CGRectZero];
self.textLabel.backgroundColor = [UIColor clearColor];
[self addSubview:self.textLabel];
}

Expand All @@ -49,41 +52,27 @@ - (void)setChecked:(BOOL)checked
- (void)drawRect:(CGRect)rect
{
CGRect frame = CGRectIntegral(CGRectMake(0, (rect.size.height - self.checkboxSideLength) / 2.0, self.checkboxSideLength, self.checkboxSideLength));
UIBezierPath *bezierPath = [UIBezierPath bezierPath];

if (self.checked) {
[bezierPath moveToPoint: CGPointMake(CGRectGetMinX(frame) + 0.75000 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.21875 * CGRectGetHeight(frame))];
[bezierPath addLineToPoint: CGPointMake(CGRectGetMinX(frame) + 0.40000 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.52500 * CGRectGetHeight(frame))];
[bezierPath addLineToPoint: CGPointMake(CGRectGetMinX(frame) + 0.28125 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.37500 * CGRectGetHeight(frame))];
[bezierPath addLineToPoint: CGPointMake(CGRectGetMinX(frame) + 0.17500 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.47500 * CGRectGetHeight(frame))];
[bezierPath addLineToPoint: CGPointMake(CGRectGetMinX(frame) + 0.40000 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.75000 * CGRectGetHeight(frame))];
[bezierPath addLineToPoint: CGPointMake(CGRectGetMinX(frame) + 0.81250 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.28125 * CGRectGetHeight(frame))];
[bezierPath addLineToPoint: CGPointMake(CGRectGetMinX(frame) + 0.75000 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.21875 * CGRectGetHeight(frame))];
UIBezierPath *bezierPath = [UIBezierPath bezierPath];

[bezierPath moveToPoint:CGPointMake(CGRectGetMinX(frame) + 0.75000 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.21875 * CGRectGetHeight(frame))];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.40000 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.52500 * CGRectGetHeight(frame))];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.28125 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.37500 * CGRectGetHeight(frame))];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.17500 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.47500 * CGRectGetHeight(frame))];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.40000 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.75000 * CGRectGetHeight(frame))];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.81250 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.28125 * CGRectGetHeight(frame))];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.75000 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.21875 * CGRectGetHeight(frame))];
[bezierPath closePath];

[self.checkboxColor setFill];
[bezierPath fill];
}

[bezierPath moveToPoint:CGPointMake(CGRectGetMinX(frame) + 0.87500 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.12500 * CGRectGetHeight(frame))];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.87500 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.87500 * CGRectGetHeight(frame))];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.12500 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.87500 * CGRectGetHeight(frame))];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.12500 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.12500 * CGRectGetHeight(frame))];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.87500 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.12500 * CGRectGetHeight(frame))];
[bezierPath closePath];
[bezierPath moveToPoint:CGPointMake(CGRectGetMinX(frame) + 0.90625 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.00000 * CGRectGetHeight(frame))];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.09375 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.00000 * CGRectGetHeight(frame))];
[bezierPath addCurveToPoint:CGPointMake(CGRectGetMinX(frame) + 0.00000 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.09375 * CGRectGetHeight(frame)) controlPoint1:CGPointMake(CGRectGetMinX(frame) + 0.04219 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.00000 * CGRectGetHeight(frame)) controlPoint2:CGPointMake(CGRectGetMinX(frame) + 0.00000 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.04219 * CGRectGetHeight(frame))];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.00000 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.90625 * CGRectGetHeight(frame))];
[bezierPath addCurveToPoint:CGPointMake(CGRectGetMinX(frame) + 0.09375 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 1.00000 * CGRectGetHeight(frame)) controlPoint1:CGPointMake(CGRectGetMinX(frame) + 0.00000 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.95781 * CGRectGetHeight(frame)) controlPoint2:CGPointMake(CGRectGetMinX(frame) + 0.04219 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 1.00000 * CGRectGetHeight(frame))];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.90625 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 1.00000 * CGRectGetHeight(frame))];
[bezierPath addCurveToPoint:CGPointMake(CGRectGetMinX(frame) + 1.00000 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.90625 * CGRectGetHeight(frame)) controlPoint1:CGPointMake(CGRectGetMinX(frame) + 0.95781 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 1.00000 * CGRectGetHeight(frame)) controlPoint2:CGPointMake(CGRectGetMinX(frame) + 1.00000 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.95781 * CGRectGetHeight(frame))];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMinX(frame) + 1.00000 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.09375 * CGRectGetHeight(frame))];
[bezierPath addCurveToPoint:CGPointMake(CGRectGetMinX(frame) + 0.90625 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.00000 * CGRectGetHeight(frame)) controlPoint1:CGPointMake(CGRectGetMinX(frame) + 1.00000 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.04219 * CGRectGetHeight(frame)) controlPoint2:CGPointMake(CGRectGetMinX(frame) + 0.95781 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.00000 * CGRectGetHeight(frame))];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMinX(frame) + 0.90625 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.00000 * CGRectGetHeight(frame))];
[bezierPath closePath];
bezierPath.miterLimit = 4;


[self.checkboxColor setFill];
[bezierPath fill];
UIBezierPath *roundedRectanglePath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(CGRectGetMinX(frame) + floor(CGRectGetWidth(frame) * 0.05000 + 0.5), CGRectGetMinY(frame) + floor(CGRectGetHeight(frame) * 0.05000 + 0.5), floor(CGRectGetWidth(frame) * 0.95000 + 0.5) - floor(CGRectGetWidth(frame) * 0.05000 + 0.5), floor(CGRectGetHeight(frame) * 0.95000 + 0.5) - floor(CGRectGetHeight(frame) * 0.05000 + 0.5)) cornerRadius:4];
roundedRectanglePath.lineWidth = 2 * self.checkboxSideLength / CTCheckboxDefaultSideLength;
[self.checkboxColor setStroke];
[roundedRectanglePath stroke];
}

- (void)layoutSubviews
Expand Down
3 changes: 2 additions & 1 deletion CTCheckboxSample/CTViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

@class CTCheckbox;

@interface CTViewController : UIViewController
@interface CTViewController : UIViewController <UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet CTCheckbox *checkbox;
@property (weak, nonatomic) IBOutlet UITextField *textField;
@property (weak, nonatomic) IBOutlet UILabel *label;

- (IBAction)blackButtonTapped:(id)sender;
Expand Down
39 changes: 29 additions & 10 deletions CTCheckboxSample/CTViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@interface CTViewController ()

@property (nonatomic, strong) CTCheckbox *checkbox2;
@property (nonatomic, strong) CTCheckbox *checkbox3;
@end

@implementation CTViewController
Expand All @@ -25,11 +26,17 @@ - (void)viewDidLoad
[self checkboxDidChanged:self.checkbox];

self.checkbox2 = [[CTCheckbox alloc] initWithFrame:CGRectMake(20.0, 200.0, 280.0, 20.0)];
self.checkbox2.textLabel.text= @"by initWithFrame:";
self.checkbox2.textLabel.text = @"by initWithFrame:";
[self.view addSubview:self.checkbox2];

self.checkbox3 = [[CTCheckbox alloc] initWithFrame:CGRectMake(20.0, 240.0, 280.0, 40.0)];
self.checkbox3.checkboxSideLength = 40.0;
self.checkbox3.textLabel.text = @"checkboxSideLength is 40.0";
[self.view addSubview:self.checkbox3];
}

- (void)checkboxDidChanged:(CTCheckbox *)checkbox {
- (void)checkboxDidChanged:(CTCheckbox *)checkbox
{
if (checkbox.checked) {
self.label.text = @"Checked";
} else {
Expand All @@ -43,23 +50,35 @@ - (void)didReceiveMemoryWarning
// Dispose of any resources that can be recreated.
}

- (IBAction)blackButtonTapped:(id)sender {
self.checkbox.checkboxColor=[UIColor blackColor];
- (IBAction)blackButtonTapped:(id)sender
{
self.checkbox.checkboxColor = [UIColor blackColor];
[self.checkbox setNeedsDisplay];
}

- (IBAction)blueButtonTapped:(id)sender {
self.checkbox.checkboxColor=[UIColor blueColor];
- (IBAction)blueButtonTapped:(id)sender
{
self.checkbox.checkboxColor = [UIColor blueColor];
[self.checkbox setNeedsDisplay];
}

- (IBAction)redButtonTapped:(id)sender {
self.checkbox.checkboxColor=[UIColor redColor];
- (IBAction)redButtonTapped:(id)sender
{
self.checkbox.checkboxColor = [UIColor redColor];
[self.checkbox setNeedsDisplay];
}

- (IBAction)textChanged:(id)sender {
self.checkbox.textLabel.text= [(UITextField *)sender text];
- (IBAction)textChanged:(id)sender
{
self.checkbox.textLabel.text = [(UITextField *)sender text];
}

#pragma mark - UITextField delegate

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}

@end
52 changes: 12 additions & 40 deletions CTCheckboxSample/en.lproj/MainStoryboard.storyboard
Original file line number Diff line number Diff line change
@@ -1,81 +1,68 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="2.0" toolsVersion="3084" systemVersion="12C3103" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" initialViewController="2">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="4514" systemVersion="13B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" initialViewController="2">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="2083"/>
<deployment defaultVersion="1280" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3747"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="5">
<objects>
<viewController id="2" customClass="CTViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="3">
<rect key="frame" x="0.0" y="20" width="320" height="548"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="w84-Ow-HeX">
<rect key="frame" x="80" y="68" width="160" height="21"/>
<rect key="frame" x="80" y="78" width="160" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" id="1v1-mg-H3z" customClass="CTCheckbox">
<rect key="frame" x="20" y="20" width="280" height="40"/>
<rect key="frame" x="20" y="30" width="280" height="40"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="MzV-rU-Ib4">
<rect key="frame" x="47" y="135" width="65" height="44"/>
<rect key="frame" x="47" y="145" width="65" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
<state key="normal" title="Black">
<color key="titleColor" red="0.19607843459999999" green="0.30980393290000002" blue="0.52156865600000002" alpha="1" colorSpace="calibratedRGB"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<state key="highlighted">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="blackButtonTapped:" destination="2" eventType="touchUpInside" id="IJ3-J8-DXy"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="2o1-Gs-Zyf">
<rect key="frame" x="130" y="135" width="65" height="44"/>
<rect key="frame" x="130" y="145" width="65" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
<state key="normal" title="Blue">
<color key="titleColor" red="0.19607843459999999" green="0.30980393290000002" blue="0.52156865600000002" alpha="1" colorSpace="calibratedRGB"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<state key="highlighted">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="blueButtonTapped:" destination="2" eventType="touchUpInside" id="yVF-r6-NYc"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="EyO-OX-kci">
<rect key="frame" x="208" y="135" width="65" height="44"/>
<rect key="frame" x="208" y="145" width="65" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
<state key="normal" title="Red">
<color key="titleColor" red="0.19607843459999999" green="0.30980393290000002" blue="0.52156865600000002" alpha="1" colorSpace="calibratedRGB"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<state key="highlighted">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="redButtonTapped:" destination="2" eventType="touchUpInside" id="ZXh-YK-qCl"/>
</connections>
</button>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" minimumFontSize="17" id="Rwf-kZ-6DK">
<rect key="frame" x="47" y="97" width="226" height="30"/>
<rect key="frame" x="47" y="107" width="226" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" returnKeyType="done"/>
<connections>
<action selector="textChanged:" destination="2" eventType="editingChanged" id="Pzz-uI-Byz"/>
<outlet property="delegate" destination="2" id="ws1-ys-JAD"/>
</connections>
</textField>
</subviews>
Expand All @@ -84,28 +71,13 @@
<connections>
<outlet property="checkbox" destination="1v1-mg-H3z" id="X7z-mk-Fho"/>
<outlet property="label" destination="w84-Ow-HeX" id="PGt-Dk-LqD"/>
<outlet property="textField" destination="Rwf-kZ-6DK" id="rzr-j1-Wco"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="4" sceneMemberID="firstResponder"/>
</objects>
</scene>
</scenes>
<classes>
<class className="CTCheckbox" superclassName="UIControl">
<source key="sourceIdentifier" type="project" relativePath="./Classes/CTCheckbox.h"/>
</class>
<class className="CTViewController" superclassName="UIViewController">
<source key="sourceIdentifier" type="project" relativePath="./Classes/CTViewController.h"/>
<relationships>
<relationship kind="action" name="blackButtonTapped:"/>
<relationship kind="action" name="blueButtonTapped:"/>
<relationship kind="action" name="redButtonTapped:"/>
<relationship kind="action" name="textChanged:"/>
<relationship kind="outlet" name="checkbox" candidateClass="CTCheckbox"/>
<relationship kind="outlet" name="label" candidateClass="UILabel"/>
</relationships>
</class>
</classes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
Expand Down

0 comments on commit 0c4e7a1

Please sign in to comment.