Skip to content
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
38 changes: 18 additions & 20 deletions Example/THLabelExample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
#define kShadowBlur1 (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 10.0 : 5.0)
#define kShadowBlur2 (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 4.0 : 2.0)

#define kStrokeColor [UIColor blackColor]
#define kStrokeSize (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 6.0 : 3.0)
#define kStrokeColor1 [UIColor colorWithRed:0.923 green:0.484 blue:0.134 alpha:1.000]
#define kStrokeSize1 (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 8.0 : 4.0)
#define kStrokeColor2 [UIColor colorWithRed:0.992 green:0.864 blue:0.367 alpha:1.000]
#define kStrokeSize2 (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 12.0 : 6.0)

#define kGradientStartColor [UIColor colorWithRed:255.0 / 255.0 green:193.0 / 255.0 blue:127.0 / 255.0 alpha:1.0]
#define kGradientEndColor [UIColor colorWithRed:255.0 / 255.0 green:163.0 / 255.0 blue:64.0 / 255.0 alpha:1.0]
Expand All @@ -29,6 +31,8 @@ @interface ViewController ()
@property (nonatomic, weak) IBOutlet THLabel *label4;
@property (nonatomic, weak) IBOutlet THLabel *label5;
@property (nonatomic, weak) IBOutlet THLabel *label6;
@property (nonatomic, weak) IBOutlet THLabel *label7;

@end

@implementation ViewController
Expand All @@ -37,19 +41,13 @@ - (void)viewDidLoad {
[super viewDidLoad];

// Demonstrate shadow blur.
self.label1.shadowColor = kShadowColor1;
self.label1.shadowOffset = kShadowOffset1;
self.label1.shadowBlur = kShadowBlur1;

[self.label1 addShadow:[THLabelShadow newWithColor:kShadowColor1 blur:kShadowBlur1 offset:kShadowOffset1 type:THLabelShadowTypeOuter]];

// Demonstrate inner shadow.
self.label2.innerShadowColor = kShadowColor1;
self.label2.innerShadowOffset = kShadowOffset2;
self.label2.innerShadowBlur = kShadowBlur2;
[self.label2 addShadow:[THLabelShadow newWithColor:kShadowColor1 blur:kShadowBlur2 offset:kShadowOffset2 type:THLabelShadowTypeInner]];

// Demonstrate stroke.
self.label3.strokeColor = kStrokeColor;
self.label3.strokeSize = kStrokeSize;

[self.label3 addStroke:[THLabelStroke newWithColor:kStrokeColor1 size:kStrokeSize1 position:THLabelStrokePositionOutside]];
// Demonstrate fill gradient.
self.label4.gradientStartColor = kGradientStartColor;
self.label4.gradientEndColor = kGradientEndColor;
Expand All @@ -58,16 +56,16 @@ - (void)viewDidLoad {
self.label5.fadeTruncatingMode = THLabelFadeTruncatingModeTail;

// Demonstrate everything.
self.label6.shadowColor = kShadowColor2;
self.label6.shadowOffset = kShadowOffset1;
self.label6.shadowBlur = kShadowBlur1;
self.label6.innerShadowColor = kShadowColor2;
self.label6.innerShadowOffset = kShadowOffset2;
self.label6.innerShadowBlur = kShadowBlur2;
self.label6.strokeColor = kStrokeColor;
self.label6.strokeSize = kStrokeSize;
[self.label6 addShadow:[THLabelShadow newWithColor:kShadowColor2 blur:kShadowBlur1 offset:kShadowOffset1 type:THLabelShadowTypeOuter]];
[self.label6 addShadow:[THLabelShadow newWithColor:kShadowColor2 blur:kShadowBlur2 offset:kShadowOffset2 type:THLabelShadowTypeInner]];

[self.label6 addStroke:[THLabelStroke newWithColor:kStrokeColor1 size:kStrokeSize1 position:THLabelStrokePositionOutside]];

self.label6.gradientStartColor = kGradientStartColor;
self.label6.gradientEndColor = kGradientEndColor;

[self.label7 addStroke:[THLabelStroke newWithColor:kStrokeColor1 size:kStrokeSize1 position:THLabelStrokePositionOutside]];
[self.label7 addStroke:[THLabelStroke newWithColor:kStrokeColor2 size:kStrokeSize2 position:THLabelStrokePositionOutside]];
}

@end
22 changes: 15 additions & 7 deletions Example/THLabelExample/en.lproj/ViewController_iPhone.xib
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="5053" systemVersion="13C64" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="5056" systemVersion="13C64" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<dependencies>
<deployment defaultVersion="1280" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/>
Expand All @@ -13,6 +13,7 @@
<outlet property="label4" destination="31" id="YXs-an-qkQ"/>
<outlet property="label5" destination="pdo-l2-749" id="aUy-Fh-cUm"/>
<outlet property="label6" destination="39" id="Bqa-Qp-AXW"/>
<outlet property="label7" destination="sWo-zZ-3zc" id="K10-a8-RMs"/>
<outlet property="view" destination="6" id="7"/>
</connections>
</placeholder>
Expand All @@ -22,42 +23,49 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Shadow Blur" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="8" customClass="THLabel">
<rect key="frame" x="20" y="40" width="280" height="60"/>
<rect key="frame" x="20" y="20" width="280" height="60"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="40"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Inner Shadow" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="1zh-zi-tg4" customClass="THLabel">
<rect key="frame" x="20" y="108" width="280" height="60"/>
<rect key="frame" x="20" y="88" width="280" height="60"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="40"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Stroke" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="23" customClass="THLabel">
<rect key="frame" x="20" y="176" width="280" height="60"/>
<rect key="frame" x="20" y="156" width="280" height="60"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="40"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Fill Gradient" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="31" customClass="THLabel">
<rect key="frame" x="20" y="244" width="280" height="60"/>
<rect key="frame" x="20" y="224" width="280" height="60"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="40"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Fade Truncating" lineBreakMode="clip" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="pdo-l2-749" customClass="THLabel">
<rect key="frame" x="20" y="312" width="280" height="60"/>
<rect key="frame" x="20" y="292" width="280" height="60"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="40"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Everything" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="39" customClass="THLabel">
<rect key="frame" x="20" y="380" width="280" height="60"/>
<rect key="frame" x="20" y="354" width="280" height="60"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="40"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Double Stroke" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="sWo-zZ-3zc" customClass="THLabel">
<rect key="frame" x="20" y="412" width="280" height="60"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="40"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
Expand Down
30 changes: 23 additions & 7 deletions THLabel/THLabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,42 @@ typedef NS_OPTIONS(NSUInteger, THLabelFadeTruncatingMode) {
THLabelFadeTruncatingModeHeadAndTail = THLabelFadeTruncatingModeHead | THLabelFadeTruncatingModeTail
};

@interface THLabel : UILabel
typedef NS_ENUM(NSInteger, THLabelShadowType) {
THLabelShadowTypeOuter,
THLabelShadowTypeInner
};

@interface THLabelShadow : NSObject
- (instancetype) initWithColor:(UIColor*)color blur:(CGFloat)blur offset:(CGSize)offset type:(THLabelShadowType)type;
+ (instancetype) newWithColor:(UIColor*)color blur:(CGFloat)blur offset:(CGSize)offset type:(THLabelShadowType)type;

@property (nonatomic, assign) CGFloat shadowBlur;
@property (nonatomic, strong) UIColor *shadowColor;
@property (nonatomic, assign) CGSize shadowOffset;
@property (nonatomic, assign) THLabelShadowType shadowType;
@end

@property (nonatomic, assign) CGFloat innerShadowBlur;
@property (nonatomic, assign) CGSize innerShadowOffset;
@property (nonatomic, strong) UIColor *innerShadowColor;
@interface THLabelStroke : NSObject
- (instancetype) initWithColor:(UIColor*)color size:(CGFloat)size position:(THLabelStrokePosition)position;
+ (instancetype) newWithColor:(UIColor*)color size:(CGFloat)size position:(THLabelStrokePosition)position;

@property (nonatomic, assign) CGFloat strokeSize;
@property (nonatomic, strong) UIColor *strokeColor;
@property (nonatomic, assign) THLabelStrokePosition strokePosition;
@end

@interface THLabel : UILabel

@property (nonatomic, assign) THLabelFadeTruncatingMode fadeTruncatingMode;
@property (nonatomic, assign) UIEdgeInsets textInsets;

@property (nonatomic, strong) UIColor *gradientStartColor;
@property (nonatomic, strong) UIColor *gradientEndColor;
@property (nonatomic, copy) NSArray *gradientColors;
@property (nonatomic, assign) CGPoint gradientStartPoint;
@property (nonatomic, assign) CGPoint gradientEndPoint;

@property (nonatomic, assign) THLabelFadeTruncatingMode fadeTruncatingMode;

@property (nonatomic, assign) UIEdgeInsets textInsets;
- (void) addShadow:(THLabelShadow *)shadow;
- (void) addStroke:(THLabelStroke *)stroke;

@end
Loading