OGeek|极客世界-中国程序员成长平台

标题: iphone - 右对齐 self.navigationItem setTitleView [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 02:32
标题: iphone - 右对齐 self.navigationItem setTitleView

我需要将 navigationItem TitleView 对齐到最右边。 (navigationItem rightBarButtonItem 通常出现的地方)

如何做到这一点?

我已经尝试过了,但没有运气,它仍然将 TitleView 放在中心:

CGRect titleViewPos = CGRectMake(300, 0, 200, 10);
self.navigationItem.titleView.frame = titleViewPos;



Best Answer-推荐答案


UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
lbl.textAlignment = UITextAlignmentRight;
lbl.backgroundColor = [UIColor clearColor];
lbl.text = @"TITLEVIEW";
self.navigationItem.titleView = lbl;

你会得到输出

enter image description here

关于iphone - 右对齐 self.navigationItem setTitleView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16296828/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4