Skip to content

Commit

Permalink
Add basic support for styling UITextView
Browse files Browse the repository at this point in the history
  • Loading branch information
schmitzc authored and Greg Musick committed Feb 18, 2014
1 parent 3a0873d commit 90b9326
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 5 deletions.
12 changes: 12 additions & 0 deletions Demo/NUIDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
89B940841671418200850A9A /* NUIViewBackground.png in Resources */ = {isa = PBXBuildFile; fileRef = 89B9404A1671418100850A9A /* NUIViewBackground.png */; };
B51BC28A169724A3004A38F8 /* UISwitch+NUI.m in Sources */ = {isa = PBXBuildFile; fileRef = B51BC289169724A3004A38F8 /* UISwitch+NUI.m */; };
B51BC28E16972527004A38F8 /* NUISwitchRenderer.m in Sources */ = {isa = PBXBuildFile; fileRef = B51BC28D16972527004A38F8 /* NUISwitchRenderer.m */; };
CB8A031017CC1F7C0065A7DD /* NUITextViewRenderer.m in Sources */ = {isa = PBXBuildFile; fileRef = CB8A030F17CC1F7C0065A7DD /* NUITextViewRenderer.m */; };
CB8A031317CC1FCB0065A7DD /* UITextView+NUI.m in Sources */ = {isa = PBXBuildFile; fileRef = CB8A031217CC1FCB0065A7DD /* UITextView+NUI.m */; };
D8E7168116B8AF4400686854 /* NUIControlRenderer.m in Sources */ = {isa = PBXBuildFile; fileRef = D8E7168016B8AF4300686854 /* NUIControlRenderer.m */; };
D8E7168516B9980300686854 /* UIControl+NUI.m in Sources */ = {isa = PBXBuildFile; fileRef = D8E7168416B9980300686854 /* UIControl+NUI.m */; };
D983DEE5169DBCCD00A3A180 /* NUIToolbarRenderer.m in Sources */ = {isa = PBXBuildFile; fileRef = D983DEE4169DBCCC00A3A180 /* NUIToolbarRenderer.m */; };
Expand Down Expand Up @@ -201,6 +203,10 @@
B51BC28C16972527004A38F8 /* NUISwitchRenderer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NUISwitchRenderer.h; sourceTree = "<group>"; };
B51BC28D16972527004A38F8 /* NUISwitchRenderer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NUISwitchRenderer.m; sourceTree = "<group>"; };
B8B8BB2BB5E6412588AE14FA /* libPods-NUIDemo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-NUIDemo.a"; sourceTree = BUILT_PRODUCTS_DIR; };
CB8A030E17CC1F7C0065A7DD /* NUITextViewRenderer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NUITextViewRenderer.h; sourceTree = "<group>"; };
CB8A030F17CC1F7C0065A7DD /* NUITextViewRenderer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NUITextViewRenderer.m; sourceTree = "<group>"; };
CB8A031117CC1FCB0065A7DD /* UITextView+NUI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UITextView+NUI.h"; sourceTree = "<group>"; };
CB8A031217CC1FCB0065A7DD /* UITextView+NUI.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UITextView+NUI.m"; sourceTree = "<group>"; };
D8E7167F16B8AF4300686854 /* NUIControlRenderer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NUIControlRenderer.h; sourceTree = "<group>"; };
D8E7168016B8AF4300686854 /* NUIControlRenderer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NUIControlRenderer.m; sourceTree = "<group>"; };
D8E7168316B9980300686854 /* UIControl+NUI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIControl+NUI.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -420,6 +426,8 @@
89B940411671418100850A9A /* NUITableViewCellRenderer.m */,
89B940421671418100850A9A /* NUITextFieldRenderer.h */,
89B940431671418100850A9A /* NUITextFieldRenderer.m */,
CB8A030E17CC1F7C0065A7DD /* NUITextViewRenderer.h */,
CB8A030F17CC1F7C0065A7DD /* NUITextViewRenderer.m */,
D983DEE3169DBCCB00A3A180 /* NUIToolbarRenderer.h */,
D983DEE4169DBCCC00A3A180 /* NUIToolbarRenderer.m */,
89B940441671418100850A9A /* NUIViewRenderer.h */,
Expand Down Expand Up @@ -473,6 +481,8 @@
4A55F08716758EDA0056753C /* UITableViewCell+NUI.m */,
4A55F08916758F360056753C /* UITextField+NUI.h */,
4A55F08A16758F360056753C /* UITextField+NUI.m */,
CB8A031117CC1FCB0065A7DD /* UITextView+NUI.h */,
CB8A031217CC1FCB0065A7DD /* UITextView+NUI.m */,
D983DEE6169DC05300A3A180 /* UIToolbar+NUI.h */,
D983DEE7169DC05300A3A180 /* UIToolbar+NUI.m */,
4A55F076167570C10056753C /* UIView+NUI.h */,
Expand Down Expand Up @@ -684,6 +694,8 @@
E291BBD7179C89470016BC1D /* NUITableViewRenderer.m in Sources */,
E291BBDA179C89710016BC1D /* UITableView+NUI.m in Sources */,
EAB69D45188625E900358420 /* NUIParserDelegate.m in Sources */,
CB8A031017CC1F7C0065A7DD /* NUITextViewRenderer.m in Sources */,
CB8A031317CC1FCB0065A7DD /* UITextView+NUI.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
4 changes: 4 additions & 0 deletions NUI/Core/NUIRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#import "NUITableViewCellRenderer.h"
#import "NUIToolbarRenderer.h"
#import "NUITextFieldRenderer.h"
#import "NUITextViewRenderer.h"
#import "NUIViewRenderer.h"
#import "NUIWindowRenderer.h"
#import "UIView+NUI.h"
Expand Down Expand Up @@ -89,6 +90,9 @@
+ (void)renderTextField:(UITextField*)textField;
+ (void)renderTextField:(UITextField*)textField withClass:(NSString*)className;

+ (void)renderTextView:(UITextView*)textView;
+ (void)renderTextView:(UITextView*)textView withClass:(NSString*)className;

+ (void)renderView:(UIView*)view;
+ (void)renderView:(UIView*)view withClass:(NSString*)className;

Expand Down
20 changes: 15 additions & 5 deletions NUI/Core/NUIRenderer.m
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@ + (void)renderTextField:(UITextField*)textField withClass:(NSString*)className
[NUITextFieldRenderer render:textField withClass:className];
}

+ (void)renderTextView:(UITextView *)textView
{
[NUITextViewRenderer render:textView withClass:@"TextView"];
}

+ (void)renderTextView:(UITextView *)textView withClass:(NSString *)className
{
[NUITextViewRenderer render:textView withClass:className];
}

+ (void)renderView:(UIView*)view
{
[NUIViewRenderer render:view withClass:@"View"];
Expand Down Expand Up @@ -265,7 +275,7 @@ + (void)rerenderView:(UIView *)view
for (UIView *subview in view.subviews) {
[self rerenderView:subview];
}

if ([view respondsToSelector:@selector(applyNUI)]){
[view applyNUI];
}
Expand All @@ -274,10 +284,10 @@ + (void)rerenderView:(UIView *)view
+ (void)setRerenderOnOrientationChange:(BOOL)rerender
{
NUIRenderer *instance = [self getInstance];

if (instance.rerenderOnOrientationChange != rerender) {
instance.rerenderOnOrientationChange = rerender;

if (rerender) {
[self addOrientationDidChangeObserver:self];
} else {
Expand Down Expand Up @@ -306,9 +316,9 @@ + (NUIRenderer*)getInstance
+ (void)orientationDidChange:(NSNotification *)notification
{
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

BOOL didReload = [NUISettings reloadStylesheetsOnOrientationChange:orientation];

if (didReload)
[NUIRenderer rerender];
}
Expand Down
1 change: 1 addition & 0 deletions NUI/Core/NUISwizzler.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ - (void)swizzleAll
[self swizzleDidMoveToWindow:[UITabBar class]];
[self swizzleDidMoveToWindow:[UITableViewCell class]];
[self swizzleDidMoveToWindow:[UITextField class]];
[self swizzleDidMoveToWindow:[UITextView class]];
[self swizzleDidMoveToWindow:[UIToolbar class]];
[self swizzleDidMoveToWindow:[UIControl class]];
[self swizzleDidMoveToWindow:[UIView class]];
Expand Down
10 changes: 10 additions & 0 deletions NUI/Core/Renderers/NUITextViewRenderer.h
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
26 changes: 26 additions & 0 deletions NUI/Core/Renderers/NUITextViewRenderer.m
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
5 changes: 5 additions & 0 deletions NUI/NUIStyle.nss
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ TextField {
border-style: rounded;
vertical-align: center;
}
TextView {
font-name: @primaryFontName;
font-color: @primaryFontColor;
font-size: 14;
}
LargeTextField {
height: 50;
font-size: 28;
Expand Down
34 changes: 34 additions & 0 deletions NUI/UI/UITextView+NUI.h
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
7 changes: 7 additions & 0 deletions NUI/UI/UITextView+NUI.m
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

0 comments on commit 90b9326

Please sign in to comment.