如何使自定义UINavigationBar图像居中

时间:2012-12-07 06:22:27

标签: ios uinavigationcontroller

所以我有一个导航栏,我想自定义和居中,无论我做什么,我都会得到像so这样的图像平铺。

以下是我用于在self.navigation.titleView

中设置UITableControllerView的代码
self.navigationItem.titleView = [self titleView]; // happens in viewDidLoad

- (UIView *)titleView{
UIImage *headerImage = [UIImage imageNamed:@"header@2x"];
UIImageView *containerView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, headerImage.size.width, headerImage.size.height)];


return containerView;

}

感谢。

1 个答案:

答案 0 :(得分:0)

UIImageView *imgtitle = [[UIImageView alloc]    initWithFrame:CGRectMake(0, 0, 100, 25)];
    [imgtitle setContentMode:UIViewContentModeCenter];
    self.navigationItem.titleView = imgtitle;
    imgtitle.image = [UIImage imageNamed:@"logo.png"];