美文网首页
iOS UIBarButtonItem 大小设置

iOS UIBarButtonItem 大小设置

作者: 桀骜不驯的搬砖者 | 来源:发表于2019-03-20 16:30 被阅读0次
问题:当我们使用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;

相关文章

网友评论

      本文标题:iOS UIBarButtonItem 大小设置

      本文链接:https://www.haomeiwen.com/subject/brhtvqtx.html