嗨,我只是制作一个自定义的导航项目标题视图,但它看起来有点不对劲。
这是自定义视图,它基于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);
}
但是当app运行时,它喜欢它,标题不在中心
屏幕截图在这里:
http://i.stack.imgur.com/yQVLr.png
答案 0 :(得分:0)
将titleLabel backgroundColor设置为[UIColor clearColor]
;