how to add items in uinavigationbar at a specific position?

后端 未结 6 857
予麋鹿
予麋鹿 2020-12-21 14:41

I am developing one application for iphone and in that i have some issues regarding adding more then one UILabel in navigation bar at a specific position.

6条回答
  •  青春惊慌失措
    2020-12-21 15:21

    Have a look at this piece of code. With some modifications it should solve your problem:

    UIButton *imageButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [imageButton setFrame:CGRectMake(15, 0, 57, 44)];
    [imageButton setBackgroundImage:[UIImage imageNamed:@"someImage.png"] forState:UIControlStateNormal];
    
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(140, 0, 250, 44)];
    [titleLabel setText:@"some title"];
    [titleLabel setBackgroundColor:[UIColor clearColor]];
    [titleLabel setTextColor:[UIColor whiteColor]];
    [titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
    
    [self.navigationController.navigationBar addSubview:imageButton];
    [self.navigationController.navigationBar addSubview:titleLabel];
    

    Just modify the values in the CGRectMake() to fit your needs.

提交回复
热议问题