iOS:如何使navigationBar titleView左对齐

时间:2015-12-12 13:04:51

标签: ios objective-c

UIView *sLineBarView = [[UIView alloc]initWithFrame:CGRectMake(0,0,1,20)];
        [sCustomTitleView addSubview:sLineBarView];
        [sLineBarView TUMMoveToVerticalCenter];
        [sLineBarView release];

        UIImage *sDropBoxImg= [UIImage imageNamed:@"bt_dropdown"];
        UIImageView *sDropDownBox = [[UIImageView alloc] initWithImage: sDropBoxImg];
        [sDropDownBox setFrame: CGRectMake(0,30, 92, 58)];
        [sDropDownBox setAlpha:1.0f];
        sDropDownBox.userInteractionEnabled = YES;
        sDropDownBox.tag = kDropBoxTag;

        [sCustomTitleView addSubview:sDropDownBox];
        [sDropDownBox release];

        UIImage *sRightImage1 = [UIImage imageNamed:@"gnb_bt_menu"];

        UIButton *sCustomBarItem0 = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20,40)];
        [sCustomBarItem0 setBackgroundImage:sRightImage1 forState:UIControlStateNormal];
        [sCustomTitleView addSubview:sCustomBarItem0];
        [sCustomBarItem0 TUMMoveToVerticalCenter];

        sViewController.navigationItem.titleView = sCustomTitleView;

我想将navigationBar titleView左对齐但没有成功。

如何使navigationBar titleView左对齐?

fream.x =负面

在我看来,这是不精确的。(因为ios版本)

1 个答案:

答案 0 :(得分:1)

增加sCustomTitleView宽度并检查,或者您可以在viewDidLoad -

中尝试此代码
UILabel* lbl = [[UILabel alloc] initWithFrame:CGRectMake(0,0,200,40)];
lbl.textAlignment = NSTextAlignmentLeft;
lbl.text = @"My Title";
self.navigationItem.titleView = lbl;