navigationItem.leftBarButtonItem的宽度怎么word调整表格宽度

问题对人有帮助,内容完整,我也想知道答案
问题没有实际价值,缺少关键内容,没有改进余地
下面是微信的导航条截图:
这是我自己做的导航条。
请问左右两边的item如何全局设置它们的大小和样式,具体该怎么做?
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
用[UINavitionBar appearance]
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
自定义UIBarButtonItem
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
自定义 UINavigaitonController
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.leftBarButtonItem = backB
customView参数传个自己写的button
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
不嫌麻烦的话可以自己写一个类继承与UIBarButtonItem,然后自己的所有barbutton都用这个类,在自己的类当中初始化的时候改变尺寸。
同步到新浪微博
分享到微博?
你好!看起来你挺喜欢这个内容,但是你还没有注册帐号。 当你创建了帐号,我们能准确地追踪你关注的问题,在有新答案或内容的时候收到网页和邮件通知。还能直接向作者咨询更多细节。如果上面的内容有帮助,记得点赞 (????)? 表示感谢。
明天提醒我
关闭理由:
删除理由:
忽略理由:
推广(招聘、广告、SEO 等)方面的内容
与已有问题重复(请编辑该提问指向已有相同问题)
答非所问,不符合答题要求
宜作评论而非答案
带有人身攻击、辱骂、仇恨等违反条款的内容
无法获得确切结果的问题
非开发直接相关的问题
非技术提问的讨论型问题
其他原因(请补充说明)
我要该,理由是:拒绝访问 |
| 百度云加速
请打开cookies.
此网站 () 的管理员禁止了您的访问。原因是您的访问包含了非浏览器特征(d43bf-ua98).
重新安装浏览器,或使用别的浏览器开发过程中,发现titleview很难居中,通过各种尝试终于找到了解决方法。
首先清楚你个概念:
1.leftBarButtonItem,导航条中左侧button。
2.rightBarButtonItem,导航条中右侧button。
3.titleview,不用介绍了吧,就是标题。
问题原因:
经过尝试,发现titleview的起点位置和尺寸依赖于leftBarButtonItem和rightBarButtonItem的位置。
解决方案:
设置titleview之前,先初始化leftBarButtonItem和rightBarButtonItem的位置,然后根据leftBarButtonItem和rightBarButtonItem的位置来使titleview居中。
//以下使参考代码。
//必须放在 leftBarButtonItem和rightBarButtonItem初始化之后调用
- (void)setDisplayCustomTitleText:(NSString*)text
& & // Init views with rects with height and y pos
& & UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
& & // Use autoresizing to restrict the bounds to the area that the titleview allows
& & titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
& & titleView.autoresizesSubviews = YES;
& & titleView.backgroundColor = [UIColorclearColor];
& & UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
& & titleLabel.tag = kUIVIEWCONTROLLER_LABEL_TAG;
& & titleLabel.backgroundColor = [UIColor clearColor];
& & titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:16];
& & titleLabel.textAlignment = UITextAlignmentCenter;
& & titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
& & titleLabel.textColor = TC_CNavigationTitleC
& & titleLabel.lineBreakMode = UILineBreakModeClip;
& & titleLabel.textAlignment = UITextAlignmentCenter;
& & titleLabel.autoresizingMask = titleView.autoresizingMask;
& & CGRect leftViewbounds = self.navigationItem.leftBarButtonItem.customView.bounds;
& & CGRect rightViewbounds = self.navigationItem.rightBarButtonItem.customView.bounds;
& & CGRect
& &&CGFloat maxWidth = leftViewbounds.size.width & rightViewbounds.size.width ? leftViewbounds.size.width : rightViewbounds.size.width;
& & maxWidth += 15;//leftview 左右都有间隙,左边是5像素,右边是8像素,加2个像素的阀值 5 + 8 + 2
& & frame = titleLabel.frame;
& & frame.size.width = 320 - maxWidth * 2;
& & titleLabel.frame =
& & frame = titleView.frame;
& & frame.size.width = 320 - maxWidth * 2;
& & titleView.frame =
& & // Set the text
& & titleLabel.text =
& &&& &&// Add as the nav bar's titleview
& & [titleView addSubview:titleLabel];
& & self.navigationItem.titleView = titleV
& & [titleView release];
& & [titleLabel release];
阅读(...) 评论()如果我们从 title 为 “首页” 的页面 A 点击进入一个子页面 B,那么在页面 B 的左上角将显示一个名为 “&首页” 的按钮。假设这个页面 A 叫 “你是我天边最美的云彩”,那在页面 B 中就会变得非常长,影响顶栏中其他元素的显示,那么该如何自定义返回按钮的文字呢?很简单:在页面 A(父级) 中加入如下代码:override func viewDidLoad() {
super.viewDidLoad()
// 定义所有子页面返回按钮的名称
navigationItem.backBarButtonItem = UIBarButtonItem(title: "返回", style: UIBarButtonItemStyle.Plain, target: nil, action: nil)
实测,6 plus 能最长显示 “你是我天边最美的” 几个字。
WRITTEN BY
程序员,Swift Contributor,正在写《iOS 可视化编程与 Auto Layout》。
相关日志:
Powered by13:33 提问
让leftbarbuttonitem右移。
用**leftBarButtonItem**,但是我想让它移动的更往右点,它现在贴在左边的位置。有什么解决办法吗?
这是Button的按钮:
[UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:[UIImage imageNamed:@"task_status.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(changeStatus:) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(80, 0,100, 18)];
self.tabBarController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
按赞数排序
UIBarButtonItem *flexBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:? action:?]
UIBarButtonItem *flexBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:&#(id)#& action:&#(SEL)#&]
试试看,记得是用 下面类型的 barbuttonItem
其他相似问题

我要回帖

更多关于 markdown表格宽度调整 的文章

 

随机推荐