UINavigationBarItem自定义 - 如何获取tabcontroller的一角?

时间:2015-04-23 04:10:05

标签: ios objective-c xcode

我想问一下如何将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];

navigationitem

1 个答案:

答案 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以解决您的问题,这可能会有帮助吗