Disable UITableView horizontal scroll

前端 未结 6 1533
梦毁少年i
梦毁少年i 2021-01-13 13:02

I created a UITableView with a small frame, like (0,0,50,50). I want to disable the horizontal scrolling but keep the vertical scrolling.

I set se

相关标签:
6条回答
  • 2021-01-13 13:14

    If you've applied tableView.contentInsetAdjustmentBehavior = , try selecting the value .scrollableAxes instead of .automatic or .always

    0 讨论(0)
  • 2021-01-13 13:16

    You can set AlwaysBounceHorizontal property of UITableView to false as follows:

    Swift:

    self.tableView.alwaysBounceHorizontal = false
    

    Objective-C:

    [self.tableView setAlwaysBounceHorizontal:NO];
    
    0 讨论(0)
  • 2021-01-13 13:21
    self.tblViewProfile.alwaysBounceHorizontal = false // using coding
    

    Or by storyboard/xib

    Un tick horizontal bounce option in storyboard or xib

    0 讨论(0)
  • 2021-01-13 13:32

    change the content size of the tableView, make sure the width of the content size is not greater than the frame size

    self.tableView.contentSize = CGSizeMake(self.tableView.frame.size.width, self.tableView.contentSize.height);
    
    0 讨论(0)
  • 2021-01-13 13:34

    If you created the table view in the interface builder then there is an option check the scroll vertically and uncheck the horizontal scroll.

    If you didn't then you should try create it in the interface builder and assign it to your IBOutlet

    Hope it helps !

    0 讨论(0)
  • 2021-01-13 13:37

    Check if the content inset property of the table view is nonzero. If so reset it to zero.

    0 讨论(0)
提交回复
热议问题