嗨,我尝试在导航栏上设置UILabels
。在potrait模式下,它适合正确,但是当我们旋转风景模式时,它不能正确适合。请帮助我。
我的代码如下:
CGRect frame = self.navigationController.navigationBar.frame;
UILabel *lbl1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width/2, 44)];
lbl1.backgroundColor = [UIColor redColor];
lbl1.textAlignment = NSTextAlignmentCenter;
lbl1.text = @"Dashboard";
UILabel *lbl2 = [[UILabel alloc] initWithFrame:CGRectMake(frame.size.width/2, 0, frame.size.width/2, 44)];
lbl2.backgroundColor = [UIColor redColor];
lbl2.textAlignment = NSTextAlignmentCenter;
lbl2.text = @"Profile";
UIView *customView = [[UIView alloc]initWithFrame:frame];
[customView addSubview:lbl1];
[customView addSubview:lbl2];
self.navigationItem.titleView = customView;
最佳答案
试试这个。
CGRect frame = self.navigationController.navigationBar.frame;
UIView *customView = [[UIView alloc]initWithFrame:frame];
customView.backgroundColor = [UIColor redColor];
[customView addSubview:lbl1];
[customView addSubview:lbl2];
self.navigationItem.titleView = customView;
关于ios - 如何在导航栏上设置UILabels,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33624520/