自定义UIBarButtonItem的问题

显示一个按钮

1
2
3
4
5
6
7
8
9
10
11
12
13
14
UIButton *editButton = [UIButton buttonWithType:UIButtonTypeCustom];

editButton.frame=CGRectMake(0, 0, 50, 30);

[editButton setBackgroundImage:[UIImage imageNamed:@"edit_off.png"] forState:UIControlStateNormal];

[editButton setBackgroundImage:[UIImage imageNamed:@"edit_on.png"] forState:UIControlStateHighlighted];

[editButton addTarget:self action:@selector(doneAction)  forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *editItem = [[UIBarButtonItem alloc] initWithCustomView:editButton];

self.navigationItem.rightBarButtonItem = editItem;

在iOS5 没有editButton.frame=CGRectMake(0, 0, 50, 30) 按钮会显示不出来。在iOS4 下 是不必须的…