Skip to content

Commit

Permalink
more button types: left and right carets, left and right arrows.
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienwindal committed Mar 6, 2014
1 parent 558be36 commit d9852b3
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

FRDLivelyButtonDemo/FRDLivelyButtonDemo.xcodeproj/project.xcworkspace/xcshareddata/FRDLivelyButtonDemo.xccheckout

FRDLivelyButtonDemo/FRDLivelyButtonDemo.xcodeproj/project.xcworkspace/xcuserdata/sebastienwindal.xcuserdatad/WorkspaceSettings.xcsettings

FRDLivelyButtonDemo/FRDLivelyButtonDemo.xcodeproj/project.xcworkspace/xcuserdata/sebastienwindal.xcuserdatad/UserInterfaceState.xcuserstate

*.xcuserstate
2 changes: 1 addition & 1 deletion FRDLivelyButton.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "FRDLivelyButton"
s.version = "1.0.1"
s.version = "1.1.0"
s.summary = "Lively button."
s.description = "Simple UIButton subclass intended to be used inside a UIBarButtonItem. Supports common nav bar button types, nicely animates button type changes and touch events."
s.homepage = "http://github.com/sebastienwindal/FRDLivelyButton"
Expand Down
Binary file not shown.
6 changes: 5 additions & 1 deletion FRDLivelyButtonDemo/FRDLivelyButtonDemo/FRDLivelyButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ typedef enum {
kFRDLivelyButtonStyleCirclePlus,
kFRDLivelyButtonStyleCircleClose,
kFRDLivelyButtonStyleCaretUp,
kFRDLivelyButtonStyleCaretDown
kFRDLivelyButtonStyleCaretDown,
kFRDLivelyButtonStyleCaretLeft,
kFRDLivelyButtonStyleCaretRight,
kFRDLivelyButtonStyleArrowLeft,
kFRDLivelyButtonStyleArrowRight
} kFRDLivelyButtonStyle;

@interface FRDLivelyButton : UIButton
Expand Down
42 changes: 42 additions & 0 deletions FRDLivelyButtonDemo/FRDLivelyButtonDemo/FRDLivelyButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ -(CGPathRef) createCenteredLineWithRadius:(CGFloat)radius angle:(CGFloat)angle o
return path;
}

-(CGPathRef) createLineFromPoint:(CGPoint)p1 toPoint:(CGPoint)p2
{
CGMutablePathRef path = CGPathCreateMutable();

CGPathMoveToPoint(path, NULL, self.offset.x + p1.x, self.offset.y + p1.y);
CGPathAddLineToPoint(path, NULL, self.offset.x + p2.x, self.offset.y + p2.y);

return path;
}

-(void) setStyle:(kFRDLivelyButtonStyle)style animated:(BOOL)animated
{
self.buttonStyle = style;
Expand Down Expand Up @@ -247,6 +257,38 @@ -(void) setStyle:(kFRDLivelyButtonStyle)style animated:(BOOL)animated
newLine1Alpha = 0.0f;
newLine2Path = [self createCenteredLineWithRadius:self.dimension/4.0f - self.line2Layer.lineWidth/2.0f angle:M_PI_4 offset:CGPointMake(self.dimension/6.0f,0.0f)];
newLine3Path = [self createCenteredLineWithRadius:self.dimension/4.0f - self.line3Layer.lineWidth/2.0f angle:3*M_PI_4 offset:CGPointMake(-self.dimension/6.0f,0.0f)];
} else if (style == kFRDLivelyButtonStyleCaretLeft) {
newCirclePath = [self createCenteredCircleWithRadius:self.dimension/20.0f];
newCircleAlpha = 0.0f;
newLine1Path = [self createCenteredLineWithRadius:self.dimension/20.0f angle:0 offset:CGPointMake(0, 0)];
newLine1Alpha = 0.0f;
newLine2Path = [self createCenteredLineWithRadius:self.dimension/4.0f - self.line2Layer.lineWidth/2.0f angle:-3*M_PI_4 offset:CGPointMake(0.0f,self.dimension/6.0f)];
newLine3Path = [self createCenteredLineWithRadius:self.dimension/4.0f - self.line3Layer.lineWidth/2.0f angle:3*M_PI_4 offset:CGPointMake(0.0f,-self.dimension/6.0f)];
} else if (style == kFRDLivelyButtonStyleCaretRight) {
newCirclePath = [self createCenteredCircleWithRadius:self.dimension/20.0f];
newCircleAlpha = 0.0f;
newLine1Path = [self createCenteredLineWithRadius:self.dimension/20.0f angle:0 offset:CGPointMake(0, 0)];
newLine1Alpha = 0.0f;
newLine2Path = [self createCenteredLineWithRadius:self.dimension/4.0f - self.line2Layer.lineWidth/2.0f angle:-M_PI_4 offset:CGPointMake(0.0f,self.dimension/6.0f)];
newLine3Path = [self createCenteredLineWithRadius:self.dimension/4.0f - self.line3Layer.lineWidth/2.0f angle:M_PI_4 offset:CGPointMake(0.0f,-self.dimension/6.0f)];
} else if (style == kFRDLivelyButtonStyleArrowLeft) {
newCirclePath = [self createCenteredCircleWithRadius:self.dimension/20.0f];
newCircleAlpha = 0.0f;
newLine1Path = [self createCenteredLineWithRadius:self.dimension/2.0f angle:M_PI offset:CGPointMake(0, 0)];
newLine1Alpha = 1.0f;
newLine2Path = [self createLineFromPoint:CGPointMake(0, self.dimension/2.0f)
toPoint:CGPointMake(self.dimension/2.0f/GOLDEN_RATIO, self.dimension/2+self.dimension/2.0f/GOLDEN_RATIO)];
newLine3Path = [self createLineFromPoint:CGPointMake(0, self.dimension/2.0f)
toPoint:CGPointMake(self.dimension/2.0f/GOLDEN_RATIO, self.dimension/2-self.dimension/2.0f/GOLDEN_RATIO)];
} else if (style == kFRDLivelyButtonStyleArrowRight) {
newCirclePath = [self createCenteredCircleWithRadius:self.dimension/20.0f];
newCircleAlpha = 0.0f;
newLine1Path = [self createCenteredLineWithRadius:self.dimension/2.0f angle:0 offset:CGPointMake(0, 0)];
newLine1Alpha = 1.0f;
newLine2Path = [self createLineFromPoint:CGPointMake(self.dimension, self.dimension/2.0f)
toPoint:CGPointMake(self.dimension - self.dimension/2.0f/GOLDEN_RATIO, self.dimension/2+self.dimension/2.0f/GOLDEN_RATIO)];
newLine3Path = [self createLineFromPoint:CGPointMake(self.dimension, self.dimension/2.0f)
toPoint:CGPointMake(self.dimension - self.dimension/2.0f/GOLDEN_RATIO, self.dimension/2-self.dimension/2.0f/GOLDEN_RATIO)];
} else {
NSAssert(FALSE, @"unknown type");
}
Expand Down
46 changes: 45 additions & 1 deletion FRDLivelyButtonDemo/FRDLivelyButtonDemo/Storyboard.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="kyS-XR-hzT" customClass="FRDLivelyButton">
<rect key="frame" x="128" y="231" width="64" height="64"/>
<rect key="frame" x="128" y="271" width="64" height="64"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
Expand Down Expand Up @@ -91,6 +91,26 @@
<action selector="changeButtonStyleAction:" destination="s51-Nb-ZXD" eventType="touchUpInside" id="1de-Ci-wpv"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="0SI-OE-MYo" customClass="FRDLivelyButton">
<rect key="frame" x="139" y="155" width="38" height="28"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="changeButtonStyleAction:" destination="s51-Nb-ZXD" eventType="touchUpInside" id="LGL-hQ-Wr0"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="glO-1c-RIY" customClass="FRDLivelyButton">
<rect key="frame" x="200" y="155" width="38" height="28"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="changeButtonStyleAction:" destination="s51-Nb-ZXD" eventType="touchUpInside" id="YBc-RL-U7x"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="euH-tP-FHV" customClass="FRDLivelyButton">
<rect key="frame" x="28" y="155" width="38" height="28"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
Expand All @@ -101,6 +121,26 @@
<action selector="changeButtonStyleAction:" destination="s51-Nb-ZXD" eventType="touchUpInside" id="bzE-8Q-cJf"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="N5n-d1-IRU" customClass="FRDLivelyButton">
<rect key="frame" x="255" y="155" width="38" height="28"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="changeButtonStyleAction:" destination="s51-Nb-ZXD" eventType="touchUpInside" id="AC9-qv-n0w"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Upr-uE-HSQ" customClass="FRDLivelyButton">
<rect key="frame" x="255" y="186" width="38" height="28"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="changeButtonStyleAction:" destination="s51-Nb-ZXD" eventType="touchUpInside" id="bBY-x3-Cae"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
Expand All @@ -111,8 +151,12 @@
<outlet property="closeButton" destination="Eri-O2-1vs" id="owB-ms-KqD"/>
<outlet property="closeCircleButton" destination="WuS-Lu-38q" id="Epq-BG-QFD"/>
<outlet property="downCaretButton" destination="JGa-di-8gl" id="a1B-0u-Qb4"/>
<outlet property="leftArrowButton" destination="N5n-d1-IRU" id="Ejz-6K-hT3"/>
<outlet property="leftCaretButton" destination="0SI-OE-MYo" id="pTg-Ig-2KD"/>
<outlet property="plusCircleButton" destination="Fnb-sA-OE9" id="O3C-0M-RGx"/>
<outlet property="plustButton" destination="79g-6E-ejR" id="MDm-rL-KaH"/>
<outlet property="rightArrowButton" destination="Upr-uE-HSQ" id="ulS-nu-Ncu"/>
<outlet property="rightCaretButton" destination="glO-1c-RIY" id="4Zv-a9-F3v"/>
<outlet property="upCaretButton" destination="euH-tP-FHV" id="VtK-OL-cYK"/>
</connections>
</viewController>
Expand Down
10 changes: 9 additions & 1 deletion FRDLivelyButtonDemo/FRDLivelyButtonDemo/TestViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ @interface TestViewController ()
@property (weak, nonatomic) IBOutlet FRDLivelyButton *closeCircleButton;
@property (weak, nonatomic) IBOutlet FRDLivelyButton *upCaretButton;
@property (weak, nonatomic) IBOutlet FRDLivelyButton *downCaretButton;
@property (weak, nonatomic) IBOutlet FRDLivelyButton *leftCaretButton;
@property (weak, nonatomic) IBOutlet FRDLivelyButton *rightCaretButton;
@property (weak, nonatomic) IBOutlet FRDLivelyButton *leftArrowButton;
@property (weak, nonatomic) IBOutlet FRDLivelyButton *rightArrowButton;

@end

Expand Down Expand Up @@ -49,6 +53,10 @@ - (void)viewDidLoad
[self.closeCircleButton setStyle:kFRDLivelyButtonStyleCircleClose animated:NO];
[self.upCaretButton setStyle:kFRDLivelyButtonStyleCaretUp animated:NO];
[self.downCaretButton setStyle:kFRDLivelyButtonStyleCaretDown animated:NO];
[self.leftCaretButton setStyle:kFRDLivelyButtonStyleCaretLeft animated:NO];
[self.rightCaretButton setStyle:kFRDLivelyButtonStyleCaretRight animated:NO];
[self.leftArrowButton setStyle:kFRDLivelyButtonStyleArrowLeft animated:NO];
[self.rightArrowButton setStyle:kFRDLivelyButtonStyleArrowRight animated:NO];

[self.bigButton setStyle:kFRDLivelyButtonStyleClose animated:YES];
[self.bigButton setOptions:@{kFRDLivelyButtonLineWidth: @(4.0f)}];
Expand Down Expand Up @@ -78,7 +86,7 @@ - (IBAction)changeButtonStyleAction:(FRDLivelyButton *)sender

- (IBAction)buttonAction:(FRDLivelyButton *)sender
{
newStyle = (newStyle + 1) % 7;
newStyle = (newStyle + 1) % 11;

[sender setStyle:newStyle animated:YES];
}
Expand Down

0 comments on commit d9852b3

Please sign in to comment.