forked from tombenner/nui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic support for styling UITextView
- Loading branch information
Showing
9 changed files
with
114 additions
and
5 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
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
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,10 @@ | ||
#import <Foundation/Foundation.h> | ||
#import <QuartzCore/QuartzCore.h> | ||
#import "NUIGraphics.h" | ||
#import "NUISettings.h" | ||
|
||
@interface NUITextViewRenderer : NSObject | ||
|
||
+ (void)render:(UITextView*)textView withClass:(NSString*)className; | ||
|
||
@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,26 @@ | ||
#import "NUITextViewRenderer.h" | ||
|
||
@implementation NUITextViewRenderer | ||
|
||
+ (void)render:(UITextView*)textView withClass:(NSString*)className | ||
{ | ||
NSString *property; | ||
|
||
property = @"font-color"; | ||
if ([NUISettings hasProperty:property withClass:className]) { | ||
textView.textColor = [NUISettings getColor:property withClass:className]; | ||
} | ||
|
||
property = @"font-size"; | ||
if ([NUISettings hasProperty:property withClass:className]) { | ||
textView.font = [textView.font fontWithSize:[NUISettings getFloat:property withClass:className]]; | ||
} | ||
|
||
property = @"font-name"; | ||
if ([NUISettings hasProperty:property withClass:className]) { | ||
textView.font = [UIFont fontWithName:[NUISettings get:property withClass:className] size:textView.font.pointSize]; | ||
} | ||
|
||
} | ||
|
||
@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
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,34 @@ | ||
#import "UITextView+NUI.h" | ||
|
||
@implementation UITextView (NUI) | ||
|
||
- (void)initNUI | ||
{ | ||
if (!self.nuiClass) { | ||
self.nuiClass = @"TextView"; | ||
} | ||
} | ||
|
||
- (void)applyNUI | ||
{ | ||
// Styling shouldn't be applied to inherited classes or to labels within other views | ||
// (e.g. UITableViewCellContentView), unless nuiClass is explictly set | ||
if (([self class] == [UILabel class] && | ||
[[self superview] class] == [UIView class]) || self.nuiClass) { | ||
[self initNUI]; | ||
if (![self.nuiClass isEqualToString:@"none"]) { | ||
[NUIRenderer renderTextView:self withClass:self.nuiClass]; | ||
} | ||
} | ||
self.nuiIsApplied = [NSNumber numberWithBool:YES]; | ||
} | ||
|
||
- (void)override_didMoveToWindow | ||
{ | ||
if (!self.nuiIsApplied) { | ||
[self applyNUI]; | ||
} | ||
[self override_didMoveToWindow]; | ||
} | ||
|
||
@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,7 @@ | ||
#import <UIKit/UIKit.h> | ||
#import <objc/runtime.h> | ||
#import "NUIRenderer.h" | ||
|
||
@interface UITextView (NUI) | ||
|
||
@end |