Skip to content

Commit

Permalink
Added support for UIBarButtonSystemItems
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanellis committed Mar 5, 2012
1 parent cd88a9c commit 475c5d3
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Pegasus/PGTranslators.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 31 additions & 2 deletions Pegasus/PGTranslators.m
Original file line number Diff line number Diff line change
Expand Up @@ -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:);
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions Pegasus/Views/PGBarButtonItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand All @@ -32,6 +38,7 @@ + (NSString *)name {
+ (NSDictionary *)properties {

NSMutableDictionary *properties =[NSMutableDictionary dictionaryWithObjectsAndKeys:
@"*", @"systemItem",
@"NSString", @"title",
@"UIBarButtonItemStyle", @"style",
nil];
Expand Down
7 changes: 3 additions & 4 deletions Pegasus/Views/PGToolbar.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 2 additions & 0 deletions Sample/PegasusSample/UI/sample6.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
<view frame="fullscreen">

<toolbar frame="{{0,420}, {320, 40}}">
<barbuttonitem systemItem="flexible-space" /> <!-- add flexible space at start to center items -->
<barbuttonitem title="one" style="bordered" />
<barbuttonitem title="two" style="bordered" />
<barbuttonitem title="three" style="bordered" />
<barbuttonitem title="four" style="bordered" />
<barbuttonitem systemItem="flexible-space" /> <!-- add flexible space at end to center items -->
</toolbar>

</view>

0 comments on commit 475c5d3

Please sign in to comment.