我想更改leftBarButtonItem的大小。
如果我使用自定义barButtonItem,那么我就不会在该按钮上获得之前的符号。
在这里,我通过在didFinishLaunchingWithOptions
方法中设置以下代码来成功制作小文本。
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:
@{NSFontAttributeName:[UIFont systemFontOfSize:12.0]} forState:UIControlStateNormal];
但之前的迹象并没有改变。
有没有办法(除了设置图像以外)制作小标志?
我也尝试改变leftBarButtonItem
的比例,但没有可用的方法。
答案 0 :(得分:1)
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;
答案 1 :(得分:0)
UIBarButtonItem* backButton = [[UIBarButtonItem alloc]initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(barButtonBackPressed:)];
UIImage *backImage = [UIImage imageNamed:@"backarrow11.png"];
UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom];
back.bounds = CGRectMake( 0, 0, 17, 17);
[back setImage:backImage forState:UIControlStateNormal];
[back addTarget:self action:@selector(barButtonBackPressed:)forControlEvents: UIControlEventTouchUpInside];
UIBarButtonItem *barBtn2 = [[UIBarButtonItem alloc] initWithCustomView:back];
self.navigationItem.leftBarButtonItems=[NSArray arrayWithObjects:barBtn2,backButton, nil];