diff --git a/samples/TTCatalog/Classes/ButtonTestController.m b/samples/TTCatalog/Classes/ButtonTestController.m index aacd0a72cd..c359a5408a 100644 --- a/samples/TTCatalog/Classes/ButtonTestController.m +++ b/samples/TTCatalog/Classes/ButtonTestController.m @@ -30,8 +30,8 @@ - (TTStyle*)embossedButton:(UIControlState)state { [TTLinearGradientFillStyle styleWithColor1:RGBCOLOR(255, 255, 255) color2:RGBCOLOR(216, 221, 231) next: [TTSolidBorderStyle styleWithColor:RGBCOLOR(161, 167, 178) width:1 next: - [TTInsetStyle styleWithInset:UIEdgeInsetsMake(0, 0, -1, 0) next: - [TTTextStyle styleWithFont:[UIFont boldSystemFontOfSize:13] + [TTInsetStyle styleWithInset:UIEdgeInsetsMake(4, 8, 4-1, 8) next: + [TTTextStyle styleWithFont:[UIFont boldSystemFontOfSize:14] color:TTSTYLEVAR(linkTextColor) shadowColor:[UIColor colorWithWhite:255 alpha:0.4] shadowOffset:CGSizeMake(0, -1) next:nil]]]]]]]; @@ -43,8 +43,8 @@ - (TTStyle*)embossedButton:(UIControlState)state { [TTLinearGradientFillStyle styleWithColor1:RGBCOLOR(225, 225, 225) color2:RGBCOLOR(196, 201, 221) next: [TTSolidBorderStyle styleWithColor:RGBCOLOR(161, 167, 178) width:1 next: - [TTInsetStyle styleWithInset:UIEdgeInsetsMake(0, 0, -1, 0) next: - [TTTextStyle styleWithFont:[UIFont boldSystemFontOfSize:13] + [TTInsetStyle styleWithInset:UIEdgeInsetsMake(4, 8, 4-1, 8) next: + [TTTextStyle styleWithFont:[UIFont boldSystemFontOfSize:14] color:[UIColor whiteColor] shadowColor:[UIColor colorWithWhite:255 alpha:0.4] shadowOffset:CGSizeMake(0, -1) next:nil]]]]]]]; } else { diff --git a/src/TTButton.m b/src/TTButton.m index 5ed2e3084c..a44caaa603 100644 --- a/src/TTButton.m +++ b/src/TTButton.m @@ -138,10 +138,10 @@ @implementation TTButton /////////////////////////////////////////////////////////////////////////////////////////////////// // class public -+ (TTButton*)buttonWithStyle:(NSString*)className title:(NSString*)title { ++ (TTButton*)buttonWithStyle:(NSString*)selector title:(NSString*)title { TTButton* button = [[[TTButton alloc] initWithFrame:CGRectZero] autorelease]; [button setTitle:title forState:UIControlStateNormal]; - [button setStylesWithClassName:className]; + [button setStylesWithSelector:selector]; return button; } @@ -403,19 +403,19 @@ - (void)setStyle:(TTStyle*)style forState:(UIControlState)state { content.style = style; } -- (void)setStylesWithClassName:(NSString*)className { +- (void)setStylesWithSelector:(NSString*)selector { TTStyleSheet* ss = [TTStyleSheet globalStyleSheet]; - TTStyle* normalStyle = [ss styleWithClassName:className forState:UIControlStateNormal]; + TTStyle* normalStyle = [ss styleWithSelector:selector forState:UIControlStateNormal]; [self setStyle:normalStyle forState:UIControlStateNormal]; - TTStyle* highlightedStyle = [ss styleWithClassName:className forState:UIControlStateHighlighted]; + TTStyle* highlightedStyle = [ss styleWithSelector:selector forState:UIControlStateHighlighted]; [self setStyle:highlightedStyle forState:UIControlStateHighlighted]; - TTStyle* selectedStyle = [ss styleWithClassName:className forState:UIControlStateSelected]; + TTStyle* selectedStyle = [ss styleWithSelector:selector forState:UIControlStateSelected]; [self setStyle:selectedStyle forState:UIControlStateSelected]; - TTStyle* disabledStyle = [ss styleWithClassName:className forState:UIControlStateDisabled]; + TTStyle* disabledStyle = [ss styleWithSelector:selector forState:UIControlStateDisabled]; [self setStyle:disabledStyle forState:UIControlStateDisabled]; } diff --git a/src/TTScrollView.m b/src/TTScrollView.m index 5fa662fda4..d93f0ff5e1 100644 --- a/src/TTScrollView.m +++ b/src/TTScrollView.m @@ -496,7 +496,6 @@ - (UIEdgeInsets)squareTouchEdges:(UIEdgeInsets)edges { CGFloat midY = edges.top + (height/2); return UIEdgeInsetsMake(midY - d/2, midX - d/2, midY + d/2, midX + d/2); - return UIEdgeInsetsMake(edges.top, edges.left, edges.top + d, edges.left + d); } } diff --git a/src/TTStyleSheet.m b/src/TTStyleSheet.m index b29f4696a3..996c6b7a77 100644 --- a/src/TTStyleSheet.m +++ b/src/TTStyleSheet.m @@ -45,19 +45,19 @@ - (void)dealloc { /////////////////////////////////////////////////////////////////////////////////////////////////// // public -- (TTStyle*)styleWithClassName:(NSString*)className { - return [self styleWithClassName:className forState:UIControlStateNormal]; +- (TTStyle*)styleWithSelector:(NSString*)selector { + return [self styleWithSelector:selector forState:UIControlStateNormal]; } -- (TTStyle*)styleWithClassName:(NSString*)className forState:(UIControlState)state { +- (TTStyle*)styleWithSelector:(NSString*)selector forState:(UIControlState)state { NSString* key = state == UIControlStateNormal - ? className - : [NSString stringWithFormat:@"%@%d", className, state]; + ? selector + : [NSString stringWithFormat:@"%@%d", selector, state]; TTStyle* style = [_styles objectForKey:key]; if (!style) { - SEL selector = NSSelectorFromString(className); - if ([self respondsToSelector:selector]) { - style = [self performSelector:selector withObject:(id)state]; + SEL sel = NSSelectorFromString(selector); + if ([self respondsToSelector:sel]) { + style = [self performSelector:sel withObject:(id)state]; if (style) { if (!_styles) { _styles = [[NSMutableDictionary alloc] init]; diff --git a/src/TTStyledText.m b/src/TTStyledText.m index 5b5bdd8db4..74d597e102 100644 --- a/src/TTStyledText.m +++ b/src/TTStyledText.m @@ -105,7 +105,7 @@ - (void)layoutFrames { style = linkStyle; } TTStyledSpanNode* span = (TTStyledSpanNode*)node; - TTStyle* spanStyle = [[TTStyleSheet globalStyleSheet] styleWithClassName:span.className]; + TTStyle* spanStyle = [[TTStyleSheet globalStyleSheet] styleWithSelector:span.className]; if (spanStyle) { style = spanStyle; } diff --git a/src/TTTableViewDataSource.m b/src/TTTableViewDataSource.m index a4056d1734..68dc737a20 100644 --- a/src/TTTableViewDataSource.m +++ b/src/TTTableViewDataSource.m @@ -209,10 +209,6 @@ @implementation TTListDataSource /////////////////////////////////////////////////////////////////////////////////////////////////// // class public -+ (TTListDataSource*)dataSourceWithObjectsArray:(NSMutableArray*)items { - return [[[self alloc] initWithItems:items] autorelease]; -} - + (TTListDataSource*)dataSourceWithObjects:(id)object,... { NSMutableArray* items = [NSMutableArray array]; va_list ap; @@ -226,6 +222,10 @@ + (TTListDataSource*)dataSourceWithObjects:(id)object,... { return [[[self alloc] initWithItems:items] autorelease]; } ++ (TTListDataSource*)dataSourceWithItems:(NSMutableArray*)items { + return [[[self alloc] initWithItems:items] autorelease]; +} + /////////////////////////////////////////////////////////////////////////////////////////////////// // NSObject @@ -314,6 +314,28 @@ + (TTSectionedDataSource*)dataSourceWithObjects:(id)object,... { return [[[self alloc] initWithItems:items sections:sections] autorelease]; } ++ (TTSectionedDataSource*)dataSourceWithArrays:(id)object,... { + NSMutableArray* items = [NSMutableArray array]; + NSMutableArray* sections = [NSMutableArray array]; + va_list ap; + va_start(ap, object); + while (object) { + if ([object isKindOfClass:[NSString class]]) { + [sections addObject:object]; + } else { + [items addObject:object]; + } + object = va_arg(ap, id); + } + va_end(ap); + + return [[[self alloc] initWithItems:items sections:sections] autorelease]; +} + ++ (TTSectionedDataSource*)dataSourceWithItems:(NSArray*)items sections:(NSArray*)sections { + return [[[self alloc] initWithItems:items sections:sections] autorelease]; +} + /////////////////////////////////////////////////////////////////////////////////////////////////// // NSObject diff --git a/src/TTThumbView.m b/src/TTThumbView.m index 8d940ebd11..315ec1af07 100644 --- a/src/TTThumbView.m +++ b/src/TTThumbView.m @@ -10,7 +10,7 @@ - (id)initWithFrame:(CGRect)frame { self.opaque = YES; self.clipsToBounds = YES; - [self setStylesWithClassName:@"thumbView:"]; + [self setStylesWithSelector:@"thumbView:"]; } return self; } diff --git a/src/Three20/TTButton.h b/src/Three20/TTButton.h index 146e4189e8..defa9e4c8d 100644 --- a/src/Three20/TTButton.h +++ b/src/Three20/TTButton.h @@ -7,7 +7,7 @@ @property(nonatomic,retain) UIFont* font; -+ (TTButton*)buttonWithStyle:(NSString*)className title:(NSString*)title; ++ (TTButton*)buttonWithStyle:(NSString*)selector title:(NSString*)title; - (NSString*)titleForState:(UIControlState)state; - (void)setTitle:(NSString*)title forState:(UIControlState)state; @@ -17,7 +17,14 @@ - (TTStyle*)styleForState:(UIControlState)state; - (void)setStyle:(TTStyle*)style forState:(UIControlState)state; -- (void)setStylesWithClassName:(NSString*)className; + +/** + * Sets the styles for all control states using a single style selector. + * + * The method for the selector must accept a single argument for the control state. It will + * be called to return a style for each of the different control states. + */ +- (void)setStylesWithSelector:(NSString*)selector; - (void)suspendLoadingImages:(BOOL)suspended; diff --git a/src/Three20/TTGlobal.h b/src/Three20/TTGlobal.h index 0707f78aca..417293293c 100644 --- a/src/Three20/TTGlobal.h +++ b/src/Three20/TTGlobal.h @@ -67,10 +67,10 @@ /////////////////////////////////////////////////////////////////////////////////////////////////// // Style helpers -#define TTSTYLE(_CLASSNAME) [[TTStyleSheet globalStyleSheet] styleWithClassName:@#_CLASSNAME] +#define TTSTYLE(_SELECTOR) [[TTStyleSheet globalStyleSheet] styleWithSelector:@#_SELECTOR] -#define TTSTYLESTATE(_CLASSNAME, _STATE) [[TTStyleSheet globalStyleSheet] \ - styleWithClassName:@#_CLASSNAME forState:_STATE] +#define TTSTYLESTATE(_SELECTOR, _STATE) [[TTStyleSheet globalStyleSheet] \ + styleWithSelector:@#_SELECTOR forState:_STATE] #define TTSTYLEVAR(_VARNAME) [(id)[TTStyleSheet globalStyleSheet] _VARNAME] diff --git a/src/Three20/TTStyleSheet.h b/src/Three20/TTStyleSheet.h index 19fa1ee7e4..847a1ce3ff 100644 --- a/src/Three20/TTStyleSheet.h +++ b/src/Three20/TTStyleSheet.h @@ -9,8 +9,8 @@ + (TTStyleSheet*)globalStyleSheet; + (void)setGlobalStyleSheet:(TTStyleSheet*)styleSheet; -- (TTStyle*)styleWithClassName:(NSString*)className; -- (TTStyle*)styleWithClassName:(NSString*)className forState:(UIControlState)state; +- (TTStyle*)styleWithSelector:(NSString*)selector; +- (TTStyle*)styleWithSelector:(NSString*)selector forState:(UIControlState)state; - (void)freeMemory; diff --git a/src/Three20/TTTableViewDataSource.h b/src/Three20/TTTableViewDataSource.h index 6d2212e01f..38af849dea 100644 --- a/src/Three20/TTTableViewDataSource.h +++ b/src/Three20/TTTableViewDataSource.h @@ -62,6 +62,7 @@ @property(nonatomic,readonly) NSMutableArray* items; + (TTListDataSource*)dataSourceWithObjects:(id)object,...; ++ (TTListDataSource*)dataSourceWithItems:(NSMutableArray*)items; - (id)initWithItems:(NSArray*)items; @@ -74,8 +75,24 @@ NSMutableArray* _items; } +/** + * Objects should be in this format: + * + * @"section title", item, item, @"section title", item, item, ... + * + */ + (TTSectionedDataSource*)dataSourceWithObjects:(id)object,...; +/** + * Objects should be in this format: + * + * @"section title", arrayOfItems, @"section title", arrayOfItems, ... + * + */ ++ (TTSectionedDataSource*)dataSourceWithArrays:(id)object,...; + ++ (TTSectionedDataSource*)dataSourceWithItems:(NSArray*)items sections:(NSArray*)sections; + - (id)initWithItems:(NSArray*)items sections:(NSArray*)sections; - (NSArray*)lettersForSectionsWithSearch:(BOOL)withSearch withCount:(BOOL)withCount; diff --git a/src/UIViewAdditions.m b/src/UIViewAdditions.m index 2615f50187..b2587aa76d 100644 --- a/src/UIViewAdditions.m +++ b/src/UIViewAdditions.m @@ -190,12 +190,12 @@ - (CGPoint)offsetFromView:(UIView*)otherView { - (CGFloat)orientationWidth { return UIDeviceOrientationIsLandscape(TTDeviceOrientation()) - ? self.height: self.width; + ? self.height : self.width; } - (CGFloat)orientationHeight { return UIDeviceOrientationIsLandscape(TTDeviceOrientation()) - ? self.width: self.height; + ? self.width : self.height; } - (UIScrollView*)findFirstScrollView {