2012-10-16 79 views
0

嗨,我只是做一個自定義的navigationitem標題視圖,但它看起來有點不對。
這裏是自定義視圖,它的基礎上的UIView
自定義navigationitem titleview錯誤的框架

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 
     // Initialization code 
     _titleLabel=[[[UILabel alloc] init] autorelease]; 
     [self addSubview:_titleLabel]; 

     _actionButton=[UIButton buttonWithType:UIButtonTypeCustom]; 
     [self addSubview:_actionButton]; 
     [_actionButton setImage:[UIImage imageNamed:@"arrow_cal_right"] forState:UIControlStateNormal]; 

    } 
    return self; 
} 
-(void)layoutSubviews{ 
    [super layoutSubviews]; 

    [_titleLabel sizeToFit]; 
    [_actionButton sizeToFit]; 

    CGFloat height=44;//MAX(_titleLabel.frame.size.height, _actionButton.frame.size.height); 
    self.frame=CGRectMake(self.frame.origin.x, 
          0, 
          _titleLabel.frame.size.width+_actionButton.frame.size.width+kMargin, 
          height); 
    _titleLabel.frame=CGRectMake(0, 
           (height-_titleLabel.frame.size.height)/2, 
           _titleLabel.frame.size.width, 
           _titleLabel.frame.size.height); 
    _actionButton.frame=CGRectMake(_titleLabel.frame.size.width+kMargin, 
            (height-_actionButton.frame.size.height)/2, 
            _actionButton.frame.size.width, 
            _actionButton.frame.size.height); 
} 


但是當應用程序運行,它喜歡的是,標題是不是在中心
屏幕截圖是在這裏:
http://i.stack.imgur.com/yQVLr.png

回答

0

set titleLabel backgroundColor as [UIColor clearColor];

相關問題