2011-09-13 251 views
1

我想用一對夫婦的技術裏德iPad應用程序使用:自定義導航控制

http://reederapp.com/ipad/

我特別想對左側導航和使用類似的佈局。

他們是怎麼做到的?它只是位於左側的標準導航控制器?項目/縮略圖的佈局只是一個自定義的表格視圖?謝謝。

回答

0

這不是標準的導航控制器。您將不得不創建自己的UIView,將其自身附加到側面,並將AutoresizingMask屬性設置爲UIViewAutoresizingFlexibleHeight。使用-drawRect:-layoutSubviews:方法使用所需按鈕設置視圖。根據您想要對自定義視圖執行多少抽象操作,您可以讓所有按鈕將消息發送到UIView,然後該視圖會將這些消息傳遞給委託人。

實施例:

@protocol SideNavigationBarDelegate 
- (void)didTapButtonAtIndex:(NSUInteger)buttonIndex; 
@end 

@interface SideNavigationBar : UIView 
@property (strong, nonatomic) id<SideNavigationBarDelegate> delegate; 

- (id)initWithDelegate:(id<SideNavigationBarDelegate>)aDelegate; 

- (void)addButtonWithIcon:(UIImage *)icon; 

- (void)removeButtonAtIndex:(NSUInteger)index; 

@end 

@implementation SideNavigationBar 
... 
- (id)initWithDelegate:(id<SideNavigationBarDelegate>)aDelegate { 
... 
    [self setDelegate:aDelegate]; 
    [self setAutoresizingMask:UIViewAutoresizingFlexibleHeight]; 
    [self setFrame:CGRectMake(0.0f, 0.0f, 44.0f, [UIScreen mainScreen].bounds.size.height])]; 
... 
} 

- (void)addButtonWithIcon:(UIImage *)icon { 
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 44.0f, 44.0f)]; 
UIImageView *iconView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 44.0f, 44.0f)]; 
[iconView setContentMode:UIViewContentModeScaleAspectFill]; 
[iconView setImage:icon]; 
[button addSubview:iconView]; 
...set the target and action for the button... 
[[self buttons] addObject:button]; 
} 

- (void)drawRect:(CGRect)rect { ...draw buttons on view... } 

@end 

至於那是一個定製的表格視圖(在這種情況下或網格視圖)的縮略圖。不要自己動手,看看這個:https://github.com/AlanQuatermain/AQGridView

相關問題