博客> iOS减小导航栏button响应范围
iOS减小导航栏button响应范围
2018-09-19 11:28 评论:0 阅读:401 wangwei1
iOS减小导航栏button响应范围
 @property(nonatomic,strong)UIButton *myrightBtn;

 可以将按钮加到一个等大的View里面,再把view 作为CustomView

 self.myrightBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 30)];

 self.myrightBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0);

 UIView *backBtnView = [[UIView alloc] initWithFrame:self.myrightBtn.bounds];

 [backBtnView addSubview:self.myrightBtn];

 [self.myrightBtn setTitle:@"发帖" forState:UIControlStateNormal];

  self.myrightBtn.titleLabel.font = [UIFont systemFontOfSize:16];

  [self.myrightBtn addTarget:self action:@selector(toClick) forControlEvents:UIControlEventTouchUpInside];

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

参考 http://blog.csdn.net/cctvzxxz1/article/details/50321021

收藏
0
sina weixin mail 回到顶部