hi i just make a custom navigationitem title view, but it looks a bit wrong.
here is the custom view ,it base on a 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);
}
but when app run, it likes that, the title isn't in the centre
screen shot is here:
https://i.stack.imgur.com/yQVLr.png
set titleLabel backgroundColor as
[UIColor clearColor]
;