diff --git a/src/Core/Styling/Categories/UIView+PXStyling.h b/src/Core/Styling/Categories/UIView+PXStyling.h index f00911a..4566ea0 100644 --- a/src/Core/Styling/Categories/UIView+PXStyling.h +++ b/src/Core/Styling/Categories/UIView+PXStyling.h @@ -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)styleable recursively:(bool)recurse; @end diff --git a/src/Core/Styling/Categories/UIView+PXStyling.m b/src/Core/Styling/Categories/UIView+PXStyling.m index 36bc6b8..4971f04 100644 --- a/src/Core/Styling/Categories/UIView+PXStyling.m +++ b/src/Core/Styling/Categories/UIView+PXStyling.m @@ -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 diff --git a/tests/UITableViewTest/UITableViewTest/Base.lproj/Main.storyboard b/tests/UITableViewTest/UITableViewTest/Base.lproj/Main.storyboard index 6242806..72c1353 100644 --- a/tests/UITableViewTest/UITableViewTest/Base.lproj/Main.storyboard +++ b/tests/UITableViewTest/UITableViewTest/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -99,6 +99,9 @@ + + + diff --git a/tests/UITableViewTest/UITableViewTest/ViewController.m b/tests/UITableViewTest/UITableViewTest/ViewController.m index f0ae773..7c3c8aa 100644 --- a/tests/UITableViewTest/UITableViewTest/ViewController.m +++ b/tests/UITableViewTest/UITableViewTest/ViewController.m @@ -7,6 +7,7 @@ // #import "ViewController.h" +#import "UIView+PXStyling.h" @interface ViewController () @end @@ -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 diff --git a/tests/UITableViewTest/UITableViewTest/ViewController2.m b/tests/UITableViewTest/UITableViewTest/ViewController2.m index 0e98625..21a856e 100644 --- a/tests/UITableViewTest/UITableViewTest/ViewController2.m +++ b/tests/UITableViewTest/UITableViewTest/ViewController2.m @@ -7,6 +7,7 @@ // #import "ViewController2.h" +#import "UIView+PXStyling.h" @interface ViewController2 () @@ -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 diff --git a/tests/UITableViewTest/UITableViewTest/default.css b/tests/UITableViewTest/UITableViewTest/default.css index 75299cf..7b4992c 100644 --- a/tests/UITableViewTest/UITableViewTest/default.css +++ b/tests/UITableViewTest/UITableViewTest/default.css @@ -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"; }