gpt4 book ai didi

ios - 如何获取 backBarButtonItem 的宽度?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:37:24 24 4
gpt4 key购买 nike

我尝试获取 backBarButtonItem 宽度:

UIBarButtonItem *leftBtn = self.navigationItem.backBarButtonItem;
UIView *view = [leftBtn valueForKey:@"view"];
CGFloat width;
if(view){
width=view.frame.size.width;
}
NSLog(@"width %f", width);

但在控制台中:宽度 0.000000

知道我可能做错了什么吗?使用 self.navigationItem.rightBarButtonItem 就可以了。

最佳答案

UIButton *addButton = [UIButton buttonWithType:UIButtonTypeCustom];
CALayer *btnLayer = [addButton layer];
[btnLayer setMasksToBounds:YES];
[btnLayer setCornerRadius:1.0f];
[addButton setFrame:CGRectMake(0, 0, 45, 30)];
[addButton setBackgroundColor:[UIColor orangeColor]];
[addButton setTitle:@"Title" forState:UIControlStateNormal];
addButton.titleLabel.font = [UIFont systemFontOfSize:14.0];
[addButton addTarget:self action:@selector(Onclickevent:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:addButton];
[self.navigationItem setRightBarButtonItem:barButtonItem];

关于ios - 如何获取 backBarButtonItem 的宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27682263/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com