Skip to content

Commit

Permalink
Merge pull request #127 from nuthinking/master
Browse files Browse the repository at this point in the history
added addStyleClass, removeStyleClass and styleClassed methods, updated ...
  • Loading branch information
Paul Colton committed Jun 23, 2014
2 parents 4e247ed + 1c54d9c commit e90788c
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/Core/Styling/Categories/UIView+PXStyling.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
@property (nonatomic, copy) NSString *styleCSS;
@property (nonatomic) PXStylingMode styleMode UI_APPEARANCE_SELECTOR;

- (void)addStyleClass:(NSString *)styleClass;
- (void)removeStyleClass:(NSString *)styleClass;
- (void)styleClassed:(NSString *)styleClass enabled:(bool)enabled;

+ (void)updateStyles:(id<PXStyleable>)styleable recursively:(bool)recurse;

@end
34 changes: 34 additions & 0 deletions src/Core/Styling/Categories/UIView+PXStyling.m
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,40 @@ - (id)valueForUndefinedKey:(NSString *)key
return (value != nil) ? value : [super valueForUndefinedKey:key];
}

- (void)addStyleClass:(NSString *)styleClass
{
if (self.styleClass){
self.styleClass = [NSString stringWithFormat:@"%@ %@", self.styleClass, [styleClass description]];
} else {
self.styleClass = [styleClass description];
}
}

- (void)removeStyleClass:(NSString *)styleClass
{
styleClass = [styleClass description];
NSMutableSet *mutSet = [NSMutableSet new];
[mutSet addObjectsFromArray:[styleClass componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]];
[mutSet removeObject:@""];
NSArray *classesToRemove = [mutSet allObjects];
NSArray *currentClasses = objc_getAssociatedObject(self, &STYLE_CLASSES_KEY);
mutSet = [[NSMutableSet alloc] initWithArray:currentClasses];
for (NSString *classToRemove in classesToRemove){
[mutSet removeObject:classToRemove];
}
NSArray *classes = [mutSet allObjects];
self.styleClass = [classes componentsJoinedByString:@" "];
}

- (void)styleClassed:(NSString *)styleClass enabled:(bool)enabled
{
if(enabled){
[self addStyleClass:styleClass];
}else{
[self removeStyleClass:styleClass];
}
}

@end

#pragma mark - Static Functions
Expand Down
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.Storyboard.XIB" version="3.0" toolsVersion="5056" systemVersion="13C64" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="f0k-Wg-Vhg">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="5056" systemVersion="13D65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="f0k-Wg-Vhg">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/>
</dependencies>
Expand Down Expand Up @@ -99,6 +99,9 @@
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="view.styleClass" value="main"/>
</userDefinedRuntimeAttributes>
<connections>
<segue destination="K4c-iK-f2J" kind="relationship" relationship="rootViewController" id="Tro-h2-sOV"/>
</connections>
Expand Down
7 changes: 7 additions & 0 deletions tests/UITableViewTest/UITableViewTest/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "ViewController.h"
#import "UIView+PXStyling.h"

@interface ViewController ()
@end
Expand Down Expand Up @@ -49,4 +50,10 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.parentViewController.view styleClassed:@"correct" enabled:(indexPath.row == 0)];
[self.parentViewController.view styleClassed:@"error" enabled:(indexPath.row != 0)];
}

@end
2 changes: 2 additions & 0 deletions tests/UITableViewTest/UITableViewTest/ViewController2.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "ViewController2.h"
#import "UIView+PXStyling.h"

@interface ViewController2 ()

Expand All @@ -22,6 +23,7 @@ - (void)viewDidLoad
[super viewDidLoad];

_data = @[ @"Sally", @"Jane", @"Marry", @"Shannon" ];
NSLog(@"Parent style class: %@", self.navigationController.view.styleClass);
}

#pragma mark - Table view data source
Expand Down
28 changes: 18 additions & 10 deletions tests/UITableViewTest/UITableViewTest/default.css
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@

pixate-config {
cache-styles: all;
}

table-view-cell:selected{
background-color: #4078BB;
}

table-view-cell {
.main table-view {
row-height: 60px;
}

#t1 table-view-cell {
background-color: yellow;
}

#t1 table-view-headerfooter-view label {
color: blue;
.correct table-view-cell {
background-color: green;
}

.error table-view-cell {
background-color: red;
}

table-view-headerfooter-view label {
font-size: 14;
font-family: "Gill Sans";
}

#t1 table-view-headerfooter-view label {
color: blue;
}

#t2 table-view-headerfooter-view label {
color: red;
font-size: 14;
font-family: "Gill Sans";
}

0 comments on commit e90788c

Please sign in to comment.