-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IPDashedBorderedView and UIAppearance support.
added dashed bordered view added UIAppearance support. added example from a .xib. modernized enum. updated podspec. updated README. reorganized file structure.
- Loading branch information
Colin Brash
committed
Jun 27, 2014
1 parent
3943d3b
commit b46ae30
Showing
9 changed files
with
238 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// IPDashedBorderedView.h | ||
// IPDashedLine | ||
// | ||
// Created by Colin Brash on 6/27/14. | ||
// Copyright (c) 2014 Intrepid Pursuits. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface IPDashedBorderedView : UIView <UIAppearanceContainer> | ||
|
||
/** | ||
How many pts into the drawing we start, from the top left. | ||
Default is 0. | ||
*/ | ||
@property (assign, nonatomic) CGFloat phase UI_APPEARANCE_SELECTOR; | ||
|
||
/** | ||
Passing an array with the values [2,3] sets a dash pattern that alternates between a | ||
2 pt lineColor painted segment and a 3 pt backgroundColor unpainted | ||
segment. Passing the values [1,3,4,2] sets the pattern to a 1-unit painted segment, | ||
a 3-unit unpainted segment, a 4-unit painted segment, and a 2-unit unpainted segment. | ||
Default is @[@2, @2]. | ||
*/ | ||
@property (strong, nonatomic) NSArray *lengthPattern UI_APPEARANCE_SELECTOR; | ||
|
||
/** | ||
Color of the dashes. Use backgroundColor for the non-dash color. | ||
Default is black. | ||
*/ | ||
@property (strong, nonatomic) UIColor *lineColor UI_APPEARANCE_SELECTOR; | ||
|
||
/** | ||
Width of the dashed lines. | ||
Default is 1. | ||
*/ | ||
@property (assign, nonatomic) CGFloat borderWidth UI_APPEARANCE_SELECTOR; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// IPDashedBorderedView.m | ||
// IPDashedLine | ||
// | ||
// Created by Colin Brash on 6/27/14. | ||
// Copyright (c) 2014 Intrepid Pursuits. All rights reserved. | ||
// | ||
|
||
#import "IPDashedBorderedView.h" | ||
|
||
@implementation IPDashedBorderedView | ||
|
||
- (id)initWithCoder:(NSCoder *)aDecoder { | ||
self = [super initWithCoder:aDecoder]; | ||
if (self) { | ||
[self commonInit]; | ||
} | ||
return self; | ||
} | ||
|
||
- (id)initWithFrame:(CGRect)frame { | ||
self = [super initWithFrame:frame]; | ||
if (self) { | ||
[self commonInit]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)commonInit { | ||
self.backgroundColor = [UIColor clearColor]; | ||
_phase = 0.0; | ||
_lineColor = [UIColor blackColor]; | ||
_lengthPattern = @[@2, @2]; | ||
_borderWidth = 1.0; | ||
} | ||
|
||
#pragma mark - | ||
|
||
- (void)drawRect:(CGRect)rect { | ||
[super drawRect:rect]; | ||
|
||
CGContextRef context = UIGraphicsGetCurrentContext(); | ||
|
||
CGContextSetLineWidth(context, self.borderWidth * [UIScreen mainScreen].scale); | ||
CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor); | ||
|
||
int count = (int)[self.lengthPattern count]; | ||
CGFloat cArrayLengthPattern[count]; | ||
for (int i = 0; i < count; ++i) { | ||
cArrayLengthPattern[i] = (CGFloat)[self.lengthPattern[i] floatValue]; | ||
} | ||
|
||
CGContextSetLineDash(context, self.phase, cArrayLengthPattern, count); | ||
CGContextMoveToPoint(context, rect.origin.x, rect.origin.y); | ||
CGContextAddLineToPoint(context, CGRectGetMaxX(rect), rect.origin.y); | ||
CGContextAddLineToPoint(context, CGRectGetMaxX(rect), CGRectGetMaxY(rect)); | ||
CGContextAddLineToPoint(context, rect.origin.x, CGRectGetMaxY(rect)); | ||
CGContextAddLineToPoint(context, rect.origin.x, rect.origin.y); | ||
CGContextStrokePath(context); | ||
} | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="5056" systemVersion="13D65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES"> | ||
<dependencies> | ||
<deployment defaultVersion="1552" identifier="iOS"/> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/> | ||
</dependencies> | ||
<objects> | ||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="IPViewController"> | ||
<connections> | ||
<outlet property="view" destination="iN0-l3-epB" id="4gJ-QB-M5N"/> | ||
</connections> | ||
</placeholder> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> | ||
<view contentMode="scaleToFill" id="iN0-l3-epB"> | ||
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<subviews> | ||
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="NtH-21-QCC" customClass="IPDashedBorderedView"> | ||
<rect key="frame" x="140" y="380" width="148" height="103"/> | ||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> | ||
<subviews> | ||
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="This label is bordered!" textAlignment="center" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" preferredMaxLayoutWidth="148" translatesAutoresizingMaskIntoConstraints="NO" id="jYn-MO-kms"> | ||
<rect key="frame" x="0.0" y="0.0" width="148" height="103"/> | ||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> | ||
<fontDescription key="fontDescription" type="system" pointSize="17"/> | ||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/> | ||
<nil key="highlightedColor"/> | ||
</label> | ||
</subviews> | ||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> | ||
</view> | ||
</subviews> | ||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> | ||
<simulatedStatusBarMetrics key="simulatedStatusBarMetrics"/> | ||
<simulatedScreenMetrics key="simulatedDestinationMetrics" type="retina4"/> | ||
</view> | ||
</objects> | ||
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Pod::Spec.new do |s| | ||
s.name = "IPDashedLineView" | ||
s.version = "1.0.0" | ||
s.version = "1.1.0" | ||
s.summary = "Simple dashed lines." | ||
s.homepage = "https://github.com/IntrepidPursuits/IPDashedLineView" | ||
s.license = { | ||
|
@@ -27,9 +27,9 @@ Pod::Spec.new do |s| | |
s.author = { "Colin Brash" => "[email protected]" } | ||
s.source = { | ||
:git => "https://github.com/IntrepidPursuits/IPDashedLineView.git", | ||
:tag => "1.0.0" | ||
:tag => "1.1.0" | ||
} | ||
s.platform = :ios, '6.1' | ||
s.source_files = 'IPDashedLineView.{h,m}' | ||
s.source_files = 'Code/*.{h,m}' | ||
s.requires_arc = true | ||
end |
Oops, something went wrong.