在UItableview上添加悬浮按钮
2017-04-22 本文已影响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;
}