2

我在 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 ...

我试过设置它但不起作用!

4

2 回答 2

5

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

这里的答案:我可以改变导航栏项目的位置吗?

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

于 2012-06-28T13:35:46.783 回答
0

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

于 2012-06-28T13:08:12.897 回答