Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

iphone - how to add items in uinavigationbar at a specific position?

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.

What i want is in following images

enter image description here

in above image there is one backbar button and one imageview as shown with arrow-mark. Other then that all white box is for difrent UILabels to show in navigation bar. There is only one UIImageView in the navigation bar and one left bar button. Now problem is that i don't know how to add multiple UILabel in navigation bar at a specific position.

Till now what i have worked is to add only button and UIImageView with the right bar button array or left bar button array, but that only add items in sequnce.

So can anyone please guide me that how can anyone add UILabels or any other item at a specific position..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...