Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Implement UI7Font and runtime patching
Browse files Browse the repository at this point in the history
issue #21
  • Loading branch information
youknowone committed Jun 22, 2013
1 parent a73c26f commit 89196cc
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 49 deletions.
6 changes: 6 additions & 0 deletions UI7Kit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
381582471771E72C0045713A /* UI7Slider.m in Sources */ = {isa = PBXBuildFile; fileRef = 381582461771E72C0045713A /* UI7Slider.m */; };
381C00AD17172CE20067C936 /* UITTextViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 381C00AB17172CE20067C936 /* UITTextViewController.m */; };
382E2206176CB72D005F0A98 /* UITPreparedCellTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 38485C5F1710974C0001A99D /* UITPreparedCellTableViewController.m */; };
383E6A831775CF0100EF7ADA /* UI7Font.m in Sources */ = {isa = PBXBuildFile; fileRef = 383E6A821775CF0100EF7ADA /* UI7Font.m */; };
38505B30176B1575004A7725 /* UI7AlertView.m in Sources */ = {isa = PBXBuildFile; fileRef = 38505B2F176B1575004A7725 /* UI7AlertView.m */; };
385CE660177009680076C02A /* UI7KitCore.m in Sources */ = {isa = PBXBuildFile; fileRef = 38013FE3176F8352003B7809 /* UI7KitCore.m */; };
3861E06B1771F9BC00AA8DE4 /* UI7ProgressView.m in Sources */ = {isa = PBXBuildFile; fileRef = 3861E06A1771F9BC00AA8DE4 /* UI7ProgressView.m */; };
Expand Down Expand Up @@ -127,6 +128,8 @@
383764D713373154007072FD /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
383764E213373155007072FD /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
383764E513373155007072FD /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
383E6A811775CF0100EF7ADA /* UI7Font.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UI7Font.h; sourceTree = "<group>"; };
383E6A821775CF0100EF7ADA /* UI7Font.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UI7Font.m; sourceTree = "<group>"; };
38485C5E1710974C0001A99D /* UITPreparedCellTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UITPreparedCellTableViewController.h; sourceTree = "<group>"; };
38485C5F1710974C0001A99D /* UITPreparedCellTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UITPreparedCellTableViewController.m; sourceTree = "<group>"; };
38505B2E176B1575004A7725 /* UI7AlertView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UI7AlertView.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -335,6 +338,8 @@
388FC1E6177345970084574E /* UI7KitPrivate.h */,
38740492176825D900C0BB18 /* UI7Utilities.h */,
38740493176825D900C0BB18 /* UI7Utilities.m */,
383E6A811775CF0100EF7ADA /* UI7Font.h */,
383E6A821775CF0100EF7ADA /* UI7Font.m */,
3886F7021770B10700890D47 /* UI7View.h */,
3886F7031770B10700890D47 /* UI7View.m */,
38017410176776020049D26C /* UI7BarButtonItem.h */,
Expand Down Expand Up @@ -606,6 +611,7 @@
3886F7011770AAD800890D47 /* UI7Stepper.m in Sources */,
3886F7041770B10800890D47 /* UI7View.m in Sources */,
3861E06B1771F9BC00AA8DE4 /* UI7ProgressView.m in Sources */,
383E6A831775CF0100EF7ADA /* UI7Font.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
6 changes: 4 additions & 2 deletions UI7Kit/UI7ActionSheet.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Copyright (c) 2013 youknowone.org. All rights reserved.
//

#import "UI7Font.h"

#import "UI7ActionSheet.h"

@interface UIActionSheet (Private)
Expand Down Expand Up @@ -130,9 +132,9 @@ - (void)showInView:(UIView *)view {
[self.buttons applyProcedureWithIndex:^(id obj, NSUInteger index) {
UIButton *button = obj; // UIAlertButton, really
if (self.cancelButtonIndex == (NSInteger)index) {
button.titleLabel.font = [UIFont iOS7SystemFontOfSize:button.titleLabel.font.pointSize weight:@"Medium"];
button.titleLabel.font = [UI7Font systemFontOfSize:button.titleLabel.font.pointSize attribute:UI7FontAttributeMedium];
} else {
button.titleLabel.font = [UIFont iOS7SystemFontOfSize:button.titleLabel.font.pointSize weight:@"Light"];
button.titleLabel.font = [UI7Font systemFontOfSize:button.titleLabel.font.pointSize attribute:UI7FontAttributeLight];
}
[button setBackgroundImage:[UIImage clearImage] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage clearImage] forState:UIControlStateHighlighted];
Expand Down
7 changes: 4 additions & 3 deletions UI7Kit/UI7AlertView.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright (c) 2013 youknowone.org. All rights reserved.
//

#import "UI7Font.h"
#import "UI7Button.h"

#import "UI7AlertView.h"
Expand Down Expand Up @@ -153,12 +154,12 @@ - (void)show {
self.titleLabel.textColor = self.bodyTextLabel.textColor = [UIColor blackColor];
self.titleLabel.shadowOffset = self.bodyTextLabel.shadowOffset = CGSizeZero;

self.titleLabel.font = [UIFont iOS7SystemFontOfSize:17.0 weight:UI7FontWeightMedium];
self.bodyTextLabel.font = [UIFont iOS7SystemFontOfSize:16.0 weight:UI7FontWeightLight];
self.titleLabel.font = [UI7Font systemFontOfSize:17.0 attribute:UI7FontAttributeMedium];
self.bodyTextLabel.font = [UI7Font systemFontOfSize:16.0 attribute:UI7FontAttributeLight];

CGFloat highest = self.frame.size.height;
for (UIAlertButton *button in self.buttons) {
button.titleLabel.font = [UIFont iOS7SystemFontOfSize:16.0 weight:UI7FontWeightLight];
button.titleLabel.font = [UI7Font systemFontOfSize:16.0 attribute:UI7FontAttributeLight];
[button setTitleColor:[UIColor iOS7ButtonTitleColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor iOS7ButtonTitleColor].highligtedColor forState:UIControlStateHighlighted];
button.titleLabel.shadowOffset = CGSizeZero;
Expand Down
9 changes: 4 additions & 5 deletions UI7Kit/UI7BarButtonItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
// Copyright (c) 2013 youknowone.org. All rights reserved.
//

#import "UIColor.h"

#import "UI7Utilities.h"
#import "UI7Font.h"

#import "UI7BarButtonItem.h"

Expand Down Expand Up @@ -49,7 +48,7 @@ - (void)_barButtonItemInitWithFont:(UIFont *)font {
}

- (void)_barButtonItemInit {
[self _barButtonItemInitWithFont:[UIFont iOS7SystemFontOfSize:17.0 weight:UI7FontWeightLight]];
[self _barButtonItemInitWithFont:[UI7Font systemFontOfSize:17.0 attribute:UI7FontAttributeLight]];
}

@end
Expand Down Expand Up @@ -87,11 +86,11 @@ - (id)initWithCoder:(NSCoder *)aDecoder {
}

- (id)initWithBarButtonSystemItem:(UIBarButtonSystemItem)systemItem target:(id)target action:(SEL)action {
UIFont *font = [UIFont iOS7SystemFontOfSize:17.0 weight:UI7FontWeightLight];
UIFont *font = [UI7Font systemFontOfSize:17.0 attribute:UI7FontAttributeLight];
switch (systemItem) {
case UIBarButtonSystemItemAdd:
self = [super initWithTitle:@"" style:UIBarButtonItemStylePlain target:target action:action];
font = [UIFont iOS7SystemFontOfSize:22.0 weight:UI7FontWeightMedium];
font = [UI7Font systemFontOfSize:22.0 attribute:UI7FontAttributeMedium];
break;
case UIBarButtonSystemItemCompose:
case UIBarButtonSystemItemReply:
Expand Down
4 changes: 3 additions & 1 deletion UI7Kit/UI7Button.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Copyright (c) 2013 youknowone.org. All rights reserved.
//

#import "UI7Font.h"

#import "UI7Button.h"

#import "UI7KitPrivate.h"
Expand All @@ -18,7 +20,7 @@ + (id)__buttonWithType:(UIButtonType)buttonType { assert(NO); return nil; }

- (void)_buttonInit {
if (self.buttonType == UIButtonTypeRoundedRect) {
self.titleLabel.font = [UIFont iOS7SystemFontOfSize:self.titleLabel.font.pointSize weight:@"Light"];
self.titleLabel.font = [UI7Font systemFontOfSize:self.titleLabel.font.pointSize attribute:UI7FontAttributeLight];
[self setBackgroundImage:[UIImage clearImage] forState:UIControlStateNormal];
}
}
Expand Down
53 changes: 53 additions & 0 deletions UI7Kit/UI7Font.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// UI7Font.h
// UI7Kit
//
// Created by Jeong YunWon on 13. 6. 22..
// Copyright (c) 2013 youknowone.org. All rights reserved.
//

#import <UI7Kit/UI7Utilities.h>

UIKIT_EXTERN NSString *UI7FontAttributeNone;
UIKIT_EXTERN NSString *UI7FontAttributeUltraLight;
UIKIT_EXTERN NSString *UI7FontAttributeUltraLightItalic;
UIKIT_EXTERN NSString *UI7FontAttributeLight;
UIKIT_EXTERN NSString *UI7FontAttributeLightItalic;
UIKIT_EXTERN NSString *UI7FontAttributeMedium;
UIKIT_EXTERN NSString *UI7FontAttributeItalic;
UIKIT_EXTERN NSString *UI7FontAttributeBold;
UIKIT_EXTERN NSString *UI7FontAttributeBoldItalic;
UIKIT_EXTERN NSString *UI7FontAttributeCondensedBold;
UIKIT_EXTERN NSString *UI7FontAttributeCondensedBlack;

@interface UI7Font : UIFont<UI7Patch>

+ (UIFont *)systemFontOfSize:(CGFloat)fontSize;
+ (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize;
+ (UIFont *)italicSystemFontOfSize:(CGFloat)fontSize;
+ (UIFont *)systemFontOfSize:(CGFloat)fontSize attribute:(NSString *)attribute;

@end

//! @deprecated Use UI7FontAttributeLight
UIKIT_EXTERN NSString *UI7FontWeightLight __deprecated;
//! @deprecated Use UI7FontAttributeMedium
UIKIT_EXTERN NSString *UI7FontWeightMedium __deprecated;
//! @deprecated Use UI7FontAttributeBold
UIKIT_EXTERN NSString *UI7FontWeightBold __deprecated;

@interface UIFont (iOS7)

+ (UIFont *)iOS7SystemFontOfSize:(CGFloat)fontSize attribute:(NSString *)attribute;

/*!
* @deprecated Use UI7Font::systemFontOfSize:
*/
+ (UIFont *)iOS7SystemFontOfSize:(CGFloat)fontSize __deprecated;
/*!
* @deprecated Use UI7Font::systemFontOfSize:attribute:
*/
+ (UIFont *)iOS7SystemFontOfSize:(CGFloat)fontSize weight:(NSString *)weight __deprecated;

@end

70 changes: 70 additions & 0 deletions UI7Kit/UI7Font.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// UI7Font.m
// UI7Kit
//
// Created by Jeong YunWon on 13. 6. 22..
// Copyright (c) 2013 youknowone.org. All rights reserved.
//

#import "UI7Font.h"

NSString *UI7FontAttributeNone = nil;
NSString *UI7FontAttributeUltraLight = @"UltraLight";
NSString *UI7FontAttributeUltraLightItalic = @"UltraLightItalic";
NSString *UI7FontAttributeLight = @"Light";
NSString *UI7FontAttributeLightItalic = @"LightItalic";
NSString *UI7FontAttributeMedium = @"Medium";
NSString *UI7FontAttributeItalic = @"Italic";
NSString *UI7FontAttributeBold = @"Bold";
NSString *UI7FontAttributeBoldItalic = @"BoldItalic";
NSString *UI7FontAttributeCondensedBold = @"CondensedBold";
NSString *UI7FontAttributeCondensedBlack = @"CondensedBlack";

@implementation UI7Font

+ (void)patch {
Class target = [UI7Font class];
[self exportSelector:@selector(systemFontOfSize:) toClass:target];
[self exportSelector:@selector(boldSystemFontOfSize:) toClass:target];
[self exportSelector:@selector(italicSystemFontOfSize:) toClass:target];
}

+ (UIFont *)systemFontOfSize:(CGFloat)fontSize {
return [self iOS7SystemFontOfSize:fontSize attribute:UI7FontAttributeNone];
}

+ (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize {
return [self iOS7SystemFontOfSize:fontSize attribute:UI7FontAttributeBold];
}

+ (UIFont *)italicSystemFontOfSize:(CGFloat)fontSize {
return [self iOS7SystemFontOfSize:fontSize attribute:UI7FontAttributeItalic];
}

+ (UIFont *)systemFontOfSize:(CGFloat)fontSize attribute:(NSString *)attribute {
return [self iOS7SystemFontOfSize:fontSize attribute:attribute];
}

@end


NSString *UI7FontWeightLight = @"Light";
NSString *UI7FontWeightMedium = @"Medium";
NSString *UI7FontWeightBold = @"Bold";

@implementation UIFont (iOS7)

+ (UIFont *)iOS7SystemFontOfSize:(CGFloat)fontSize attribute:(NSString *)attribute {
NSString *fontName = attribute ? [@"HelveticaNeue-%@" format:attribute] : @"Helvetica Neue";
return [UIFont fontWithName:fontName size:fontSize];
}

+ (UIFont *)iOS7SystemFontOfSize:(CGFloat)fontSize {
return [self iOS7SystemFontOfSize:fontSize attribute:nil];
}

+ (UIFont *)iOS7SystemFontOfSize:(CGFloat)fontSize weight:(NSString *)weight {
return [self iOS7SystemFontOfSize:fontSize attribute:weight];
}

@end
1 change: 1 addition & 0 deletions UI7Kit/UI7Kit.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#import <UI7Kit/UI7KitCore.h>
#import <UI7Kit/UI7Utilities.h>

#import <UI7Kit/UI7Font.h>
#import <UI7Kit/UI7AlertView.h>
#import <UI7Kit/UI7ActionSheet.h>
#import <UI7Kit/UI7BarButtonItem.h>
Expand Down
10 changes: 6 additions & 4 deletions UI7Kit/UI7KitCore.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ - (id)init {
return self;
}

- (void)dealloc {
self.tintColor = nil;
[super dealloc];
}

+ (UI7Kit *)kit {
return UI7KitSharedObject;
}
Expand All @@ -36,6 +41,7 @@ + (void)initialize {

+ (void)patch {
for (NSString *className in @[
@"UI7Font",
@"UI7ViewController",
@"UI7TableView",
@"UI7TableViewCell",
Expand All @@ -56,10 +62,6 @@ + (void)patch {
]) {
Class class = NSClassFromString(className);
[class patch];
#if DEBUG
NSLog(@"patched? %@", [class name]);
assert([class respondsToSelector:@selector(patchIfNeeded)]);
#endif
}
}

Expand Down
3 changes: 2 additions & 1 deletion UI7Kit/UI7NavigationBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright (c) 2013 youknowone.org. All rights reserved.
//

#import "UI7Font.h"
#import "UI7BarButtonItem.h"

#import "UI7NavigationBar.h"
Expand Down Expand Up @@ -39,7 +40,7 @@ - (void)_navigationBarInit {
[self setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];
[self setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsLandscapePhone];
[self setTitleTextAttributes:@{
UITextAttributeFont: [UIFont iOS7SystemFontOfSize:17.0 weight:UI7FontWeightMedium],
UITextAttributeFont: [UI7Font systemFontOfSize:17.0 attribute:UI7FontAttributeMedium],
UITextAttributeTextColor: [UIColor blackColor],
UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetZero],
}];
Expand Down
4 changes: 3 additions & 1 deletion UI7Kit/UI7SegmentedControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@

#import <QuartzCore/QuartzCore.h>

#import "UI7Font.h"
#import "UI7View.h"

#import "UI7SegmentedControl.h"

#import "UI7KitPrivate.h"
Expand All @@ -51,7 +53,7 @@ - (void)_segmentedControlInit {
UIImage *selectedBackgroundImage = [UIImage roundedImageWithSize:CGSizeMake(10.0f, 40.0f) color:[UIColor clearColor] radius:UI7ControlRadius];

NSDictionary *attributes = @{
UITextAttributeFont: [UIFont iOS7SystemFontOfSize:13.0 weight:@"Medium"],
UITextAttributeFont: [UI7Font systemFontOfSize:13.0 attribute:UI7FontAttributeMedium],
UITextAttributeTextColor: self.tintColor,
UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetZero],
};
Expand Down
4 changes: 3 additions & 1 deletion UI7Kit/UI7TabBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Copyright (c) 2013 youknowone.org. All rights reserved.
//

#import "UI7Font.h"

#import "UI7TabBar.h"

@interface UITabBar (Private)
Expand Down Expand Up @@ -40,7 +42,7 @@ - (void)_tabBarInit {
self.shadowImage = [UIImage clearImage];
}
// private properties
[self _setLabelFont:[UIFont iOS7SystemFontOfSize:10.0 weight:@"Light"]];
[self _setLabelFont:[UI7Font systemFontOfSize:10.0 attribute:UI7FontAttributeLight]];
[self _setLabelShadowOffset:CGSizeZero];
[self _setLabelTextColor:[UIColor grayColor] selectedTextColor:self.tintColor];
}
Expand Down
10 changes: 6 additions & 4 deletions UI7Kit/UI7TableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Copyright (c) 2013 youknowone.org. All rights reserved.
//

#import "UI7Font.h"

#import "UI7TableView.h"

@implementation UITableView (Patch)
Expand Down Expand Up @@ -87,7 +89,7 @@ CGFloat UI7TableViewDelegateHeightForFooterInSection(id self, SEL _cmd, UITableV
view.backgroundColor = [UIColor iOS7BackgroundColor];

view.text = [@" " stringByAppendingString:title];
view.font = [UIFont iOS7SystemFontOfSize:14.0 weight:UI7FontWeightBold];
view.font = [UI7Font systemFontOfSize:14.0 attribute:UI7FontAttributeBold];
return view;
}

Expand All @@ -101,7 +103,7 @@ CGFloat UI7TableViewDelegateHeightForFooterInSection(id self, SEL _cmd, UITableV
UILabel *view = [[[UILabel alloc] initWithFrame:CGRectMake(.0, .0, tableView.frame.size.width, height)] autorelease];
view.backgroundColor = [UIColor iOS7BackgroundColor];
view.text = [@" " stringByAppendingString:title]; // TODO: do this pretty later
view.font = [UIFont iOS7SystemFontOfSize:14.0 weight:UI7FontWeightBold];
view.font = [UI7Font systemFontOfSize:14.0 attribute:UI7FontAttributeBold];
return view;
}

Expand Down Expand Up @@ -173,8 +175,8 @@ - (id)__initWithCoder:(NSCoder *)aDecoder { assert(NO); return nil; }
- (id)__initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { assert(NO); return nil; }

- (void)_tableViewCellInit {
self.textLabel.font = [UIFont iOS7SystemFontOfSize:18.0 weight:UI7FontWeightLight];
self.detailTextLabel.font = [UIFont iOS7SystemFontOfSize:17.0 weight:UI7FontWeightLight]; // FIXME: not sure
self.textLabel.font = [UI7Font systemFontOfSize:18.0 attribute:UI7FontAttributeLight];
self.detailTextLabel.font = [UI7Font systemFontOfSize:17.0 attribute:UI7FontAttributeLight]; // FIXME: not sure
self.textLabel.highlightedTextColor = self.textLabel.textColor;
self.detailTextLabel.highlightedTextColor = self.detailTextLabel.textColor; // FIXME: not sure
self.selectedBackgroundView = [UIColor colorWith8bitWhite:217 alpha:255].image.view;
Expand Down

0 comments on commit 89196cc

Please sign in to comment.