0
從iPhone應用開發(最近9個月)開始,我只使用了IB。我有一個項目可以由另一位開發人員構建,我需要針對iPhone屏幕進行優化。在IB中沒有問題,我知道如何做到這一點,但在這個項目中,導航欄只是使用代碼添加的,並且是圖像視圖。有人可以告訴我在IB未使用時如何調整/定位導航欄嗎?我試圖增強這個應用程序的iPhone 5屏幕。如何在沒有IB的情況下添加大小調整
#define BAR_FRAME CGRectMake(0,0,320.0f,43.0f)
@implementation ICNavbarView
@synthesize homeButton=__homeButton;
@synthesize prevButton=__prevButton;
@synthesize nextButton=__nextButton;
@synthesize delegate=__delegate;
- (id)initWithFrame:(CGRect)frame
{
LogCmd();
self = [super initWithFrame:BAR_FRAME];
if (self) {
self.backgroundColor = [UIColor clearColor];
self.alpha = 0.9f;
// Add Navigation bar background // <<<<<< navigation bar from ui image
UIImageView *bgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"BgNavBarNew"]];
[self addSubview:bgView];
// Add back button
__prevButton = [UIButton buttonWithType:UIButtonTypeCustom];
__prevButton.frame = CGRectMake(30.0f, 6.0f, 29.0f, 31.0f);
UIImage *prevButtonPressed = [UIImage imageNamed:@"BtnPrevPressed"];
[__prevButton setImage:[UIImage imageNamed:@"BtnPrev"] forState:UIControlStateNormal];
[__prevButton setImage:prevButtonPressed forState:UIControlStateSelected];
[__prevButton setImage:prevButtonPressed forState:UIControlStateHighlighted];
[__prevButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:__prevButton];
// Add next button
__nextButton = [UIButton buttonWithType:UIButtonTypeCustom];
__nextButton.frame = CGRectMake(262.0f, 6.0f, 29.0f, 31.0f);
UIImage *nextButtonPressed = [UIImage imageNamed:@"BtnNextPressed"];
[__nextButton setImage:[UIImage imageNamed:@"BtnNext"] forState:UIControlStateNormal];
[__nextButton setImage:nextButtonPressed forState:UIControlStateSelected];
[__nextButton setImage:nextButtonPressed forState:UIControlStateHighlighted];
[__nextButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:__nextButton];
// Add home button
__homeButton = [UIButton buttonWithType:UIButtonTypeCustom];
__homeButton.frame = CGRectMake(145.0f, 6.0f, 31.0f, 30.0f);
UIImage *homeButtonPressed = [UIImage imageNamed:@"BtnHomePressed"];
[__homeButton setImage:[UIImage imageNamed:@"BtnHome"] forState:UIControlStateNormal];
[__homeButton setImage:homeButtonPressed forState:UIControlStateSelected];
[__homeButton setImage:homeButtonPressed forState:UIControlStateHighlighted];
[__homeButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:__homeButton];
}
return self;
}
- (id)init
{
return [self initWithFrame:CGRectZero];
}
#pragma mark - Button handlers
- (void)buttonPressed:(id)sender
{
if (sender == __prevButton) {
[self.delegate performSelector:@selector(navBarPrevButtonPressed)];
} else if (sender == __homeButton) {
[self.delegate performSelector:@selector(navBarHomeButtonPressed)];
} else {
[self.delegate performSelector:@selector(navBarNextButtonPressed)];
}
}
@end
到目前爲止,我試過UIViewAutoresizingFlexibleHeight;
這樣
// Add Navigation bar background
UIImageView *bgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"BgNavBarNew"]];
[self addSubview:bgView];
//resize
bgView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
這似乎是沒有區別的導航欄沒有移動
我以前用過這個
將您的評論標記爲正確,因爲您對父視圖的評論引導我進行修復。謝謝 – JSA986