更改rightBarButtonItem的起始y轴

时间:2012-06-28 13:04:16

标签: iphone uibarbuttonitem

我在rightBarButtonItem上有以下自定义按钮

UIButton *button1 = [[UIButton alloc] init];
button1.frame=CGRectMake(0,0,105,30);
[button1 setBackgroundImage:[UIImage imageNamed: @"image1.png"] forState:UIControlStateNormal];
[button1 addTarget:appDelegate action:@selector(Open_Link1) forControlEvents:UIControlEventTouchUpInside];

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button1];
[button1 release];

我需要将rightBarButtonItem向上移动2 px ...

我已尝试设置它但不起作用!

2 个答案:

答案 0 :(得分:5)

button1.imageEdgeInsets = UIEdgeInsetsMake(-4, 0, 0, 0);

答案在这里:Can I change the position of navigationbar item?

请注意,您更改了要分配给rightBarButtonItem的按钮的插入内容,而不是rightBarButtonItem本身。

答案 1 :(得分:0)

尝试将此button1.frame=CGRectMake(0,0,105,30);更改为button1.frame=CGRectMake(0,-2,105,30);