`
ydbc
  • 浏览: 716187 次
  • 性别: Icon_minigender_1
  • 来自: 大连
文章分类
社区版块
存档分类
最新评论

自定义title 后导致的坐标无法居中 问题解决方案

 
阅读更多

//Overide the drawing of the background UINavigationBar

@implementation UINavigationBar (CustomImage)


- (Class)class

{

returnNSClassFromString(@"HFNavigationBar");

}


- (void)drawRect:(CGRect)rect

{

UIImage *image = [UIImageimageNamed:@"navigation@2x.png"];

[image drawInRect:CGRectMake(self.bounds.origin.x,self.bounds.origin.y,self.bounds.size.width,self.bounds.size.height+5) ];

self.tintColor = [UIColorclearColor];

}



//title居中 否则会根据lefttile righttitle存在与否进行变化

-(void)layoutSubviews {

[superlayoutSubviews];

for (id viewinself.subviews) {

if ([viewisKindOfClass:NSClassFromString(@"UILabel")]) {

// Do whatever you want with view here

[viewsetFrame:CGRectMake(0 ,0,320,44) ];

}

}

}

@end




titleLabel.backgroundColor = [UIColorclearColor];

titleLabel.font = [UIFontboldSystemFontOfSize:22.0];

titleLabel.shadowColor = [UIColorcolorWithWhite:0.0alpha:0.5];

titleLabel.textAlignment =UITextAlignmentCenter;

titleLabel.textColor = [UIColorwhiteColor];// change this color

[titleLabelsetAutoresizingMask:UIViewAutoresizingNone ];

self.navigationItem.titleView =titleLabel;


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics