scorpiozj
scorpiozj

Reputation: 2687

Disable UITableView horizontal scroll

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 self.table.bounces = NO, but the tableview can't be vertically scrolled, either. As a result, the animation is not so perfect.

So anyone has tips?

thanks!

Upvotes: 5

Views: 9532

Answers (7)

Zeeshan Ahmad II
Zeeshan Ahmad II

Reputation: 1193

Check if the content inset horizontal property (Left,Right) of the table view is nonzero. If so reset it to zero.

tableView.contentInset = .init(top: 0,
                               left: (this must be) 0,
                               bottom: 0,
                               right: (this must be) 0)

Upvotes: 0

Insh
Insh

Reputation: 1

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

Upvotes: 0

Luiz Dias
Luiz Dias

Reputation: 1980

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

Swift:

self.tableView.alwaysBounceHorizontal = false

Objective-C:

[self.tableView setAlwaysBounceHorizontal:NO];

Upvotes: 1

KPK
KPK

Reputation: 160

self.tblViewProfile.alwaysBounceHorizontal = false // using coding

Or by storyboard/xib

Un tick horizontal bounce option in storyboard or xib

Upvotes: 0

lazymind
lazymind

Reputation: 74

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

Upvotes: 6

wattson12
wattson12

Reputation: 11174

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);

Upvotes: 5

shawndreck
shawndreck

Reputation: 2069

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 !

Upvotes: -1

Related Questions