问题:当我们使用UIButton传给initWithCustomView的方法来使用,你会发现这个自定义的button的大小是不受控制的,修改它的frame并不会起作用。你会发现,它还是系统默认的大小。
解决:initWithCustomView:传人的是 UIView 类型,然后试着传人一个 UIView 试试,是好使的。所以在外层包装一层 UIView 就行了
UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeSystem];
[rightBtn setImage:IMG(@"xx.png") forState:UIControlStateNormal];
[rightBtn addTarget:self action:@selector(xxxClick) forControlEvents:UIControlEventTouchUpInside];
UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 25, 25)];
[rightView addSubview:rightBtn];
UIBarButtonItem *rightBarBtn = [[UIBarButtonItem alloc] initWithCustomView:rightView];
self.navigationItem.rightBarButtonItem = rightBarBtn;
网友评论