我创建了4个带图像的BarButtons,当我添加到导航栏时。它显示了项目之间的巨大差距,以及如何消除图像之间的差距。
答案 0 :(得分:1)
你可以通过维护这样的图像插入来实现这一点: -
UIBarButtonItem *demoButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"demo.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(saveStyle)];
demoButton.imageInsets = UIEdgeInsetsMake(0.0, 0.0, 0, -60);
答案 1 :(得分:0)
固定项目可以帮助你维持你的差距。将图像添加到按钮。
UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
fixedItem.width = 10.;
UIButton *button1 = [[UIButton alloc]initWithFrame:CGRectMake(0., 0., 44., 44)];
UIBarButtonItem *barButton1 = [[UIBarButtonItem alloc]initWithCustomView: button1];
UIButton *button2 = [[UIButton alloc]initWithFrame:CGRectMake(46., 0., 44., 44)];
UIBarButtonItem *barButton2 = [[UIBarButtonItem alloc]initWithCustomView: button2];
UIButton *button3 = [[UIButton alloc]initWithFrame:CGRectMake(95., 0., 44., 44)];
UIBarButtonItem *barButton3 = [[UIBarButtonItem alloc]initWithCustomView: button3];
NSArray *itemArray = [[NSArray alloc] initWithObjects: barButton1, fixedItem, barButton2, fixedItem, barButton3, nil];
self.navigationItem.rightBarButtonItems = itemArray;