在iOS导航栏上放置标签,按钮

erd*_*mgc 4 uinavigationbar uibutton uibarbuttonitem uilabel ios

我创建了自定义导航控制器,

我想添加,左边的日期,右边的后退按钮和后退按钮旁边的标题.

我试图添加一个标签,但它不起作用.请告诉我一个方法

 UINavigationBar *naviBarObj = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 1024, 66)];


UILabel *navLabel = [[UILabel alloc] initWithFrame:CGRectMake(20,8,280,30)];
navLabel.text = @"My Text";

[self.navigationController.navigationBar addSubview:navLabel];

[self.view addSubview:naviBarObj];
Run Code Online (Sandbox Code Playgroud)

Kas*_*ame 6

UINavigationBar *naviBarObj = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 1024, 66)];

    UILabel *navLabel = [[UILabel alloc] initWithFrame:CGRectMake(200,8,200,30)];
    navLabel.text = @"My Text";
    navLabel.textColor = [UIColor redColor];
    [naviBarObj addSubview:navLabel];
    [navLabel setBackgroundColor:[UIColor clearColor]];
    [self.view addSubview:naviBarObj];
Run Code Online (Sandbox Code Playgroud)

尝试这个它会工作.它适合我:)