how to add items in uinavigationbar at a specific position?

后端 未结 6 848
予麋鹿
予麋鹿 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:41

    you can add Multiple UIlabel or Image as look like bellow image:-

    enter image description here

    this can do using bellow code you can change Label and imageView frame and put as your requirement

    - (void)viewDidLoad
    {
    
        UIView *btn = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];
    
        UILabel *label;
        label = [[UILabel alloc] initWithFrame:CGRectMake(5, 25, 200, 16)];
        label.tag = 1;
        label.backgroundColor = [UIColor clearColor];
        label.font = [UIFont boldSystemFontOfSize:16];
        label.adjustsFontSizeToFitWidth = NO;
        label.textAlignment = UITextAlignmentLeft;
        label.textColor = [UIColor whiteColor];
        label.text = @"My first lable";
        label.highlightedTextColor = [UIColor whiteColor];
        [btn addSubview:label];
        [label release];
    
        label = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, 200, 16)];
        label.tag = 2;
        label.backgroundColor = [UIColor clearColor];
        label.font = [UIFont boldSystemFontOfSize:16];
        label.adjustsFontSizeToFitWidth = NO;
        label.textAlignment = UITextAlignmentRight;
        label.textColor = [UIColor whiteColor];
        label.text = @"second line";
        label.highlightedTextColor = [UIColor whiteColor];
        [btn addSubview:label];
        [label release];
    
    
        UIImageView *imgviw=[[UIImageView alloc]initWithFrame:CGRectMake(170, 10, 20, 20)];
         imgviw.backgroundColor = [UIColor blackColor];
        imgviw.image=[UIImage imageNamed:@"a59117c2eb511d911cbf62cf97a34d56.png"];
         [btn addSubview:imgviw];
    
        self.navigationItem.titleView = btn;
    
    }
    

提交回复
热议问题