美文网首页
在UItableview上添加悬浮按钮

在UItableview上添加悬浮按钮

作者: 纯阳子_ | 来源:发表于2017-04-22 16:15 被阅读96次
- (void)viewDidLoad {
  [self.tableView addSubview:self.publishButton];
  [self.tableView bringSubviewToFront:self.publishButton];
   buttonY=(int)self.publishButton.frame.origin.y;
}

//设置代理方法

 -(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    _publishButton.frame = CGRectMake(_publishButton.frame.origin.x, buttonY+self.tableView.contentOffset.y , _publishButton.frame.size.width, _publishButton.frame.size.height);
}

//懒加载button

  -(UIButton *)publishButton//发布按钮
  {
      if (!_publishButton) {
          CGFloat width = 80 * CURRENTSIZE;
          CGFloat height = 80 * CURRENTSIZE;
          CGFloat x = CGRectGetWidth(self.view.frame) - width - 32  *CURRENTSIZE ;
          CGFloat y =CGRectGetHeight(self.view.frame) - width * 5;
    
        _publishButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _publishButton.frame = CGRectMake(x, y, width, height);
        [_publishButton setImage:[UIImage imageNamed:@"publish"] forState:UIControlStateNormal];
        [_publishButton addTarget:self action:@selector(publishButton:) forControlEvents:UIControlEventTouchUpInside];
    }
        return _publishButton;
}

相关文章

网友评论

      本文标题:在UItableview上添加悬浮按钮

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