0

嗨,我只是制作了一个自定义导航项标题视图,但看起来有点不对劲。
这是自定义视图,它基于 uiview

- (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

4

1 回答 1

0

将 titleLabel 背景颜色设置为[UIColor clearColor];

于 2012-10-16T07:36:10.537 回答