我想问一下如何将navigationtabbaritem的图标设置到左角(左:0)和右角(右:0)。
我的代码:
_custombtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
_custombtn.backgroundColor = [UIColor redColor];
[_custombtn setBackgroundImage:[UIImage imageNamed:@"ic_msg.png"]forState:UIControlStateNormal];
[_custombtn addTarget:self action:@selector(viewBn:) forControlEvents:UIControlEventTouchUpInside];
self.csbtn = [[UIBarButtonItem alloc]initWithCustomView:_custombtn];
答案 0 :(得分:0)
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
aButton.frame = CGRectMake(0.0, 0.0, 44, 44);
UIBarButtonItem *aBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:aButton];
[aButton addTarget:self action:@selector(rightBarButtonAction:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *spaceFix = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:NULL];
spaceFix.width = -10;
self.navigationItem.rightBarButtonItems = @[spaceFix, aBarButtonItem];
请添加spaceFix
以解决您的问题,这可能会有帮助吗