我想更改leftBarButtonItem的大小。如果我使用自定义的barButtonItem,那么我不会在该按钮上获得前一个的迹象。

在这里,我通过在didFinishLaunchingWithOptions方法中设置以下代码成功制作了小文本。

[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:
     @{NSFontAttributeName:[UIFont systemFontOfSize:12.0]} forState:UIControlStateNormal];

但是以前的迹象没有改变。

有什么办法(除设置图像外)缩小该标志?
我也尝试过更改leftBarButtonItem的比例,但是没有可用的方法来更改。

最佳答案

UIView *viewLeftSide = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 30.0)];
viewLeftSide.userInteractionEnabled = YES;

UIButton *btn1 = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 5.0, 20.0, 20.0)];
[btn1 setImage:[UIImage imageNamed:@"img1"] forState:UIControlStateNormal];
[btn1 addTarget:self action:@selector(sel1) forControlEvents:UIControlEventTouchUpInside];
[viewLeftSide addSubview:btn1];

UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(50.0, 5.0, 20.0, 20.0)];
[btn2 setImage:[UIImage imageNamed:@"img2"] forState:UIControlStateNormal];
[btn2 addTarget:self action:@selector(sel2) forControlEvents:UIControlEventTouchUpInside];
[viewLeftSide addSubview:btn2];

UIBarButtonItem *leftBarItem = [[UIBarButtonItem alloc] initWithCustomView:viewLeftSide];

self.tabBarController.navigationItem.leftBarButtonItem = leftBarItem;

10-08 06:10