我在这里尝试了几乎所有答案,如何删除我使用的代码下面显示的两个uibarbuttons之间的空白
UIButton *backBTN= [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[backBTN addTarget:self action:@selector(backACT:) forControlEvents:UIControlEventTouchUpInside];
[backBTN setBackgroundImage:[UIImage imageNamed:@"menu_icon.png"] forState:UIControlStateNormal];
UIBarButtonItem *backkb = [[UIBarButtonItem alloc] initWithCustomView:backBTN];
// self.navigationItem.leftBarButtonItem = backkb;
UIButton *homeBTN= [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[homeBTN addTarget:self action:@selector(homeACT:) forControlEvents:UIControlEventTouchUpInside];
[homeBTN setBackgroundImage:[UIImage imageNamed:@"logout_btn.png"] forState:UIControlStateNormal];
UIBarButtonItem *btnhome = [[UIBarButtonItem alloc] initWithCustomView:homeBTN];
// btnhome.imageInsets = UIEdgeInsetsMake(-10, 0, 0, 0);
[self.navigationItem setLeftBarButtonItems:[NSArray arrayWithObjects: backkb, btnhome, nil]];
self.navigationItem.hidesBackButton = YES;
答案 0 :(得分:2)
试试这个,
// Create a UIView to add both buttons
UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 30)];
UIButton *backBTN= [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[backBTN addTarget:self action:@selector(backACT:) forControlEvents:UIControlEventTouchUpInside];
[backBTN setBackgroundImage:[UIImage imageNamed:@"menu_icon.png"] forState:UIControlStateNormal];
//Add button to UIView
[leftView addSubview:backBTN];
UIButton *homeBTN= [[UIButton alloc] initWithFrame:CGRectMake(30, 0, 30, 30)];
[homeBTN addTarget:self action:@selector(homeACT:) forControlEvents:UIControlEventTouchUpInside];
[homeBTN setBackgroundImage:[UIImage imageNamed:@"logout_btn.png"] forState:UIControlStateNormal];
//Add button to UIView
[leftView addSubview:homeBTN];
//Set UIView as CustomView for bar button
UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftView];
[self.navigationItem setLeftBarButtonItems:[NSArray arrayWithObjects: leftBarButton, nil]];
self.navigationItem.hidesBackButton = YES;
我试过这个并输出为 使用一些背景颜色来了解边界