diff --git a/Pegasus/PGTranslators.h b/Pegasus/PGTranslators.h index 505cf6f..84f35f0 100644 --- a/Pegasus/PGTranslators.h +++ b/Pegasus/PGTranslators.h @@ -48,7 +48,8 @@ + (UITableViewStyle)tableViewStyleWithString:(NSString *)string; + (UITableViewCellSeparatorStyle)tableViewCellSeparatorStyleWithString:(NSString *)string; + (UIButtonType)buttonTypeWithString:(NSString *)string; -+ (UIBarButtonItemStyle)buttonItemStyleWithString:(NSString *)string; ++ (UIBarButtonItemStyle)barButtonItemStyleWithString:(NSString *)string; ++ (UIBarButtonSystemItem)barButtonSystemItemWithString:(NSString *)string; #pragma mark - Translators (Objects) + (NSString *)stringWithString:(NSString *)string; diff --git a/Pegasus/PGTranslators.m b/Pegasus/PGTranslators.m index 064a157..5ae0dad 100644 --- a/Pegasus/PGTranslators.m +++ b/Pegasus/PGTranslators.m @@ -47,7 +47,8 @@ + (SEL)translatorForType:(NSString *)type { // if ([type isEqualToString:@"UITableViewStyle"]) return @selector(tableViewStyleWithString:); if ([type isEqualToString:@"UITableViewCellSeparatorStyle"]) return @selector(tableViewCellSeparatorStyleWithString:); // if ([type isEqualToString:@"UIButtonType"]) return @selector(buttonTypeWithString:); - if ([type isEqualToString:@"UIBarButtonItemStyle"]) return @selector(buttonItemStyleWithString:); + if ([type isEqualToString:@"UIBarButtonItemStyle"]) return @selector(barButtonItemStyleWithString:); + //if ([type isEqualToString:@"UIBarButtonSystemItem"]) return @selector(barButtonSystemItemWithString:); // Objects: if ([type isEqualToString:@"NSString"]) return @selector(stringWithString:); @@ -208,13 +209,41 @@ + (UIButtonType)buttonTypeWithString:(NSString *)string { return 0; } -+ (UIBarButtonItemStyle)buttonItemStyleWithString:(NSString *)string { ++ (UIBarButtonItemStyle)barButtonItemStyleWithString:(NSString *)string { if ([string isEqualToString:@"plain"]) return UIBarButtonItemStylePlain; if ([string isEqualToString:@"bordered"]) return UIBarButtonItemStyleBordered; if ([string isEqualToString:@"done"]) return UIBarButtonItemStyleDone; return 0; } ++ (UIBarButtonSystemItem)barButtonSystemItemWithString:(NSString *)string { + if ([string isEqualToString:@"done"]) return UIBarButtonSystemItemDone; + if ([string isEqualToString:@"cancel"]) return UIBarButtonSystemItemCancel; + if ([string isEqualToString:@"edit"]) return UIBarButtonSystemItemEdit; + if ([string isEqualToString:@"save"]) return UIBarButtonSystemItemSave; + if ([string isEqualToString:@"add"]) return UIBarButtonSystemItemAdd; + if ([string isEqualToString:@"flexible-space"]) return UIBarButtonSystemItemFlexibleSpace; + if ([string isEqualToString:@"fixed-space"]) return UIBarButtonSystemItemFixedSpace; + if ([string isEqualToString:@"compose"]) return UIBarButtonSystemItemCompose; + if ([string isEqualToString:@"reply"]) return UIBarButtonSystemItemReply; + if ([string isEqualToString:@"action"]) return UIBarButtonSystemItemAction; + if ([string isEqualToString:@"organize"]) return UIBarButtonSystemItemOrganize; + if ([string isEqualToString:@"bookmarks"]) return UIBarButtonSystemItemBookmarks; + if ([string isEqualToString:@"search"]) return UIBarButtonSystemItemSearch; + if ([string isEqualToString:@"refresh"]) return UIBarButtonSystemItemRefresh; + if ([string isEqualToString:@"stop"]) return UIBarButtonSystemItemStop; + if ([string isEqualToString:@"camera"]) return UIBarButtonSystemItemCamera; + if ([string isEqualToString:@"trash"]) return UIBarButtonSystemItemTrash; + if ([string isEqualToString:@"play"]) return UIBarButtonSystemItemPlay; + if ([string isEqualToString:@"pause"]) return UIBarButtonSystemItemPause; + if ([string isEqualToString:@"rewind"]) return UIBarButtonSystemItemRewind; + if ([string isEqualToString:@"fast-forward"]) return UIBarButtonSystemItemFastForward; + if ([string isEqualToString:@"undo"]) return UIBarButtonSystemItemUndo; + if ([string isEqualToString:@"redo"]) return UIBarButtonSystemItemRedo; + if ([string isEqualToString:@"page-curl"]) return UIBarButtonSystemItemPageCurl; + return 0; +} + #pragma mark - Translators (Objects) + (NSString *)stringWithString:(NSString *)string { diff --git a/Pegasus/Views/PGBarButtonItem.m b/Pegasus/Views/PGBarButtonItem.m index e2bf685..45e2cbc 100644 --- a/Pegasus/Views/PGBarButtonItem.m +++ b/Pegasus/Views/PGBarButtonItem.m @@ -22,6 +22,12 @@ @implementation PGBarButtonItem + (id)internalViewWithAttributes:(NSDictionary *)attributes { + NSString *systemItemStr = [[attributes objectForKey:@"systemItem"] lowercaseString]; + if (systemItemStr) { + UIBarButtonSystemItem systemItem = [PGTranslators barButtonSystemItemWithString:systemItemStr]; + return [[UIBarButtonItem alloc] initWithBarButtonSystemItem:systemItem target:nil action:NULL]; + } + return [[UIBarButtonItem alloc] init]; } @@ -32,6 +38,7 @@ + (NSString *)name { + (NSDictionary *)properties { NSMutableDictionary *properties =[NSMutableDictionary dictionaryWithObjectsAndKeys: + @"*", @"systemItem", @"NSString", @"title", @"UIBarButtonItemStyle", @"style", nil]; diff --git a/Pegasus/Views/PGToolbar.m b/Pegasus/Views/PGToolbar.m index 219b52a..219452f 100644 --- a/Pegasus/Views/PGToolbar.m +++ b/Pegasus/Views/PGToolbar.m @@ -46,10 +46,9 @@ - (void)addSubview:(PGView *)subview { if ([subview isKindOfClass:[PGBarButtonItem class]]) { UIToolbar *toolbar = (UIToolbar *)view; - - NSMutableArray *items = [NSMutableArray arrayWithArray:toolbar.items]; - [items addObject:subview.view]; - toolbar.items = items; + + if (!toolbar.items) toolbar.items = [NSArray array]; + toolbar.items = [toolbar.items arrayByAddingObject:subview.view]; } else { [super addSubview:subview]; diff --git a/Sample/PegasusSample/UI/sample6.xml b/Sample/PegasusSample/UI/sample6.xml index 28e49d3..bb67a77 100644 --- a/Sample/PegasusSample/UI/sample6.xml +++ b/Sample/PegasusSample/UI/sample6.xml @@ -24,10 +24,12 @@ + + \ No newline at end of file