I try to change the size (the width) of a table viewcontroller (the panel with text over syria):
I have tried :
-(void)viewWillAppear:(BOOL)animated
{
self.tableView.frame = CGRectMake(0, 310, self.view.frame.size.width,200);
}
but it doesn't work. Do you know how can I reduce the width of the TableView ?
Thanks for your help !
You will have to add the table view as a subview to your view controllers view with the new size in viewWillAppear
Check the view frame width to make sure it is actually less than 320 before setting it. Most likely you are setting the table view width back to 320 which is the entire width.
Also if you are just setting the width of the table I would recommend doing the following.
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
CGRect tableViewFrame = self.tableView.frame;
tableViewFrame.width = 250;
self.tableView.frame = tableViewFrame;
}
Related
How can I adjust my tableview height programmatically in viewdidload? actually I have a view in my app I want that whe view will load then uivew will be hide ang tableview height will be increase? How it can be done? I had added these lines in viewdidload but nothing happens?
- (void)viewDidLoad {
[super viewDidLoad];
CGRect tableFrame = [tableListView frame];
tableFrame.size.height = 127;
[tableListView setFrame:tableFrame];
}
Below is my screen shot I want to hide that greycolourview and want to increase my tableview height.
Give this a shot:
1.
This should be your constraints on the tableView:
2.
//declare a constraint outlet and connect it
IBOutlet NSLayoutConstraint *constraintGrayViewBottom;
3.
This is the bottom constraint of that gray view i.e: constraintGrayViewBottom.
Select the bottom constraint as shown and on the right, click-drag the referencing outlet connection to the viewController and connect it to constraintGrayViewBottom.
4.
Handle the constraint changes as example:
-(void)viewDidAppear:(BOOL)animated {
constraintGrayViewBottom.constant = -60;
[UIView animateWithDuration:1
animations:^{
[self.view layoutIfNeeded];
}];
}
The structure of my storyboard is:
a--b--c,d,e
a is a navigation controller
b is a tab bar controller
c,d,e are tab views
c is a table view controller contains about ten cells.
when i scrolled up, the position of the last cell and the tab bar is overlapped.
How to set the position of the last cell so that it can lay up the tab bar so that we can touch it?
Thank you.
Add this in your tableview controller, the main goal is to decrease your table height.
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
CGFloat tabBarHeight = self.tabBarController.tabBar.frame.size.height;
CGRect frame = self.tableView.frame;
frame.size.height -= tabBarHeight;
self.tableView.frame = frame;
}
The above code will result in a gray tabBar. And each time switching tab will decrease table height, so moving the above code to viewDidLoad, and set the tabBar translucent to NO.
Solution 1:
CGFloat tabBarHeight = self.tabBarController.tabBar.frame.size.height;
CGRect frame = self.view.frame;
frame.size.height -= tabBarHeight;
self.view.frame = frame;
self.tabBarController.tabBar.translucent = NO;
Alternatively, you can configure tableView's contentInset in viewDidLoad.
Solution 2:
self.tableView.contentInset = UIEdgeInsetsMake(0.0f, 0.0f, CGRectGetHeight(self.tabBarController.tabBar.frame), 0.0f);
The problem is that the TableView height is incorrect.
You have to set the constraints of the TableView so the bottom of the tableView to be at the beginning of the TabBar.
I have an UIScrollView and horizontally scrollable content. I can properly set up the content size, etc, but I need to place another similar ScrollView just below the first one. So, I need to make height of the ScrollView to be equal to height of its content. Currently I use this code, but it does not work. I attached screenshot with issue and the code:
//setting the correct content size of scrollView (self.contentSize is already calculated)
self.imageScrollView.contentSize = self.contentSize;
//creating temporary CGRect
CGRect frame = self.imageScrollView.frame;
//Changing the height and re-assigning new frame to imageScrollView
frame.size.height = self.contentSize.height;
self.imageScrollView.frame = frame;
Look at the screenshot: the imageScrollView is just below NavBar. The content still scrollable and the size of ScrollView is smaller than content size.
You can't set the frame's height using frame.size.height = self.contentSize.height;
Instead use frame = CGRectMake(x, y, width, height); Ex:
self.imageScrollView.frame = CGRectMake(self.imageScrollView.frame.origin.x, self.imageScrollView.frame.origin.y, self.imageScrollView.frame.size.width, self.contentSize.height);
And from the looks of things, I suspect the content size of your imageScrollView is correct, but it's being hidden by your nav bar. In which case, I recommend setting imageScrollView frame's origin to the height of the nav bar, ex:
self.imageScrollView.frame = CGRectMake(self.imageScrollView.frame.origin.x, self.navigationController.navigationBar.frame.size.height, self.imageScrollView.frame.size.width, self.contentSize.height);
Update #1: Here's a link to a great answer explaining why you can't set the frame in the way you've attempted: ios frame change one property (eg width)
So basically you can edit a lone CGRect structure by changing a single property, but you can NOT update a CGRect in that way if it's a property of another object -- in this case a property of a frame.
Update #2: Also, to change the position of elements in your interface, place the code in viewDidLayoutSubviews, not in viewDidLoad.
Update #3: To have the code in viewDidLayoutSubviews only processed once, enclose it in a conditional, ex:
bool subviewsLaidout;
- (void)viewDidLoad {
subviewsLaidout = NO;
}
- (void)viewDidLayoutSubviews {
if (!subviewsLaidout) {
self.imageScrollView.frame = CGRectMake(self.imageScrollView.frame.origin.x, self.navigationController.navigationBar.frame.size.height, self.imageScrollView.frame.size.width, self.contentSize.height);
subviewsLaidout = YES;
}
}
I have a UITableViewController with a UIView at the bottom. (using storyboard). My UIView is set to hidden and changes state afterwards on click of button. First, I was trying to resize (increase height basically) my UIView on IBAction(buttonClick) using self.concluidoView.frame = CGRectMake(0, 0, 320, 50); but UIView was disappearing instead.
Now, it is correctly expanding UIView with the following code inside IBAction:
[UIView animateWithDuration:1.0
animations:^{
CGRect frame = self.concluidoView.frame;
frame.size.height += 100.0;
self.concluidoView.frame = frame;
}
completion:^(BOOL finished){
// complete
}];
The problem is that my UITableViewController is not scrolling enough to the new size, since the UIView is the last item in my tableView.
I've tried a few things to solve this problem, including manually trying to resize tableview to increase it's height to the same value of the UIViewincrease. I used the following code:
CGRect tableFrame = self.tableview.frame;
tableFrame.size.height += 100;
self.tableView.frame = tableFrame;
[self.tableview layoutIfNeeded];
The scrolling capacity of my tableviewwas actually smaller after this code. I would like to resize tableviewand allow scrolling, either manually, since I know how much my subviewwill increase, or automatically.
If you change the UITableView's frame, all you'll do is make it extend off screen most likely. What you want to do is get the table view to recognize that the UIView is larger. I'm assuming this UIView is the tableFooterView of your UITableView. Try doing the following:
UIView *footerView = self.tableView.tableFooterView;
self.tableView.tableFooterView = nil;
self.tableView.tableFooterView = footerView;
That will force the UITableView to reexamine the size of the footer view. I've had to do this before when changing the size of a footer view before.
I want to add a view to the bottom of the content view of both a collection view and table view (and hence is applicable to any kind of scroll view) and I also want to be able to scroll down to see this view e.g.:
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
// Observe change in content size so can move my view when
// content size changes (keep it at the bottom)
[self addObserver:self forKeyPath:#"contentSize"
options:(NSKeyValueObservingOptionPrior)
context:nil];
CGRect frame = CGRectMake(0, 0, 200, 30);
self.loadingView = [[UIView alloc] initWithFrame:frame];
[self.loadingView setBackgroundColor:[UIColor blackColor]];
[self addSubview:self.loadingView];
// Increase height of content view so that can scroll to my view.
self.contentSize = CGSizeMake(self.contentSize.width, self.contentSize.height+30);
}
return self;
}
However when, for example, a cell is inserted the contentSize is recalculated and whilst my view is still visible at the bottom of the content size (due to being able to bounce the scroll view) I can no longer scroll to it.
How do I ensure that the content size stays, as in my code, 30 points taller?
An additional question is:
is there any other way to track content size other than observing it?
Thanks in advance.
I have tried:
- (void)layoutSubviews
{
[super layoutSubviews];
self.contentSize = CGSizeMake(self.contentSize.width, self.contentSize.height+30);
}
However this causes all sorts of display issues.
If i understand correctly, you want to show a loading view in the tableView (f.e.) at the bottom. You could add an extra UITableViewCell containing this LoaderView to the tableView.
(Must change the numberOfRowsInTableView)
In another perspective for scrollViews: Use smaller bounds then the content itself, to make it scrollable. For example frame = fullscreen. At every cell adding or modification in subviews (adding) contentSize = content size + 30 px.
Try making a subclass of the scroll view and override the contentSize getter to return always 30 px more.
- (CGSize)contentSize {
CGSize customContentSize = super.contentSize;
customContentSize.height += 30;
return customContentSize;
}
(I'm writing the code by memory, there may be errors)