Je suis en UILabel
développer une application pour iPhone et en ce que j'ai quelques problèmes concernant l'ajout de plus d'un UILabel
dans la barre de navigation à un post spécifique.
Ce que je veux est dans les images suivantes
dans l'image ci-dessus il y a un button de barre arrière et un imageview
comme montré avec la flèche. Autre alors que toute la boîte blanche est pour UILabels UILabels
à montrer dans la barre de navigation. Il n'y a qu'un seul UIImageView
dans la barre de navigation et un button de barre de gauche. Maintenant le problème est que je ne sais pas comment append plusieurs UILabel
dans la barre de navigation à une position spécifique.
Jusqu'à présent, ce que j'ai travaillé est d'append seulement le button et UIImageView
avec le tableau de buttons de la barre de droite ou le tableau de buttons de la barre de gauche, mais cela n'ajoute que des éléments dans la séquence.
Alors quelqu'un peut-il me guider s'il vous plaît comment quelqu'un peut append UILabels ou tout autre élément à un post spécifique ..
vous pouvez append Multiple UIlabel ou Image comme l'image ci-dessous: –
cela peut faire en utilisant le code ci-dessous, vous pouvez changer le cadre Label et imageView et mettre en tant que votre exigence
- (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; }
Vous pouvez append des sous-vues directement à la barre de navigation –
UINavigationBar *navBar = navController.navigationBar; [navBar addSubview: yourLabel];
L'origine de l'image yourLabel sera relative à la barre de navigation
Essayez ce code
UIView *buttonContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 44)]; buttonContainer.backgroundColor = [UIColor clearColor]; UIButton *button0 = [UIButton buttonWithType:UIButtonTypeCustom]; [button0 setFrame: CGRectMake(160, 7 , 40, 30)]; [button0 setTitle:@"Sort" forState:UIControlStateNormal]; button0.titleLabel.font = [UIFont fontWithName:@"Helvetica" size:12]; [button0 setBackgroundImage:[UIImage imageNamed:@"Btn_Sort_Btn_Sort_Places.png"] forState:UIControlStateNormal]; [button0 addTarget:self action:@selector(sortAction) forControlEvents:UIControlEventTouchUpInside]; [button0 setShowsTouchWhenHighlighted:YES]; [buttonContainer addSubview:button0]; self.navigationItem.titleView = buttonContainer; UILabel *lbl_title = [[UILabel alloc] initWithFrame:CGRectMake(10, 0 , 140, 40)]; lbl_title.text = str_HeaderTitle; lbl_title.textColor = [UIColor whiteColor]; lbl_title.font = [UIFont fontWithName:@"Helvetica-Bold" size:16]; lbl_title.backgroundColor = [UIColor clearColor]; lbl_title.textAlignment = NSTextAlignmentCenter; [buttonContainer addSubview:lbl_title];
Vous pouvez définir une vue arbitraire au lieu du titre d'un controller de vue:
myViewController.navigationItem.titleView = someView;
Notez que le cadre de la vue sera probablement restreint pour faire de la place pour leftBarButtonItem
et rightBarButtonItem
.
UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(50, 2, 20, 15)]; [label setBackgroundColor:[UIColor greenColor]]; UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(40, 20, 150, 10)]; [imgView setBackgroundColor:[UIColor redColor]]; [[self.navigationController navigationBar] addSubview:label]; [self.navigationController.navigationBar addSubview:imgView];
Jetez un oeil à ce morceau de code. Avec quelques modifications, cela devrait résoudre votre problème:
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];
Il suffit de modifier les valeurs dans le CGRectMake()
pour répondre à vos besoins.