I have 2 UITableView in my UIViewController. one of them is in the right side of the screen till center of screen. The other is from center till left bound.
User can hide the right UITableview by pressing one a button on the navigation bar.
I use this code to make left UITableview full screen:
self.rightTableView.hidden= YES;
self.leftTable.frame= CGRectMake(0,
self.dataTableView.frame.origin.y,
self.view.frame.size.width,
self.dataTableView.frame.size.height);
But it is not working.
I even put this code on the viewdidload and viewDidAppear methods but the frame not changing.
Try self.leftTable.translatesAutoresizingMaskIntoConstraints = YES, then call to frame resize at runtime is automatically translated into new constraints.
But, translatesAutoresizingMaskIntoConstraints will also cause new constraints to be added based on the view's autoresizingMask. So make sure other constraints are working properly.
When using autolayout, modifying the frame will have no effect.
Instead, you should modify the constraints.
You can do this by creating outlets for your constraints and connecting then in the interface builder.
Related
I have a view within my app that has a UIPickerView. The delegation and datasource is set up and the picker loads data correctly, however, it ignores storyboard constraints entirely and shifts to the top of the view regardless of what I've tried.
The screenshots below show the alignment in storyboard (the picker is aligned center vertical/horizontal to the blue view (which has a constraint of 30 on all sides) and the alignment when the app is run on a 6S.
Any idea what I'm doing wrong?
UIPickerView has a fussy implementation of setFrame: -it only allows itself to be rendered in a handful of sizes. The easiest way to control/overcome this is to put it in a container view and apply your constraints to that view. You could override layoutSubviews in that containerView in order to center the picker, perhaps even applying a transform to scale it. Don't try to set the size of the pickerview in this code, just query (get) it and then calculate around that value.
Remove [self.view addSubview:self.mouthpiecePicker]; This is re-adding the picker view, but it was already added with Storyboard. When you re-add it, it removed all constraints.
I'm trying to update the position and size of several UIButtons in my app by using:
-(void)viewDidAppear:(BOOL)animated {
_UIButton1.frame = CGRectMake(-7, 35, 212, 77);
_UIButton2.frame = CGRectMake(139, 149, 290, 77);
// And so on for several more buttons
}
However, when I use this code, these buttons just appear at wherever the location is set on the Storyboard, not where I'm setting it programmatically. How would I make these buttons appear at a location this is different than the one I have set in my Storyboard?
Open your storyboard file and make sure the right pane is showing the Utilities menu, then uncheck Use Auto Layout.
When Auto Layout is enabled, you have to set constraints on your views and create outlets to those constraints to move things around with code. If you want to work directly with frames, Auto Layout needs to be turned off. It has to be one or the other.
Auto Layout can be great, but it's hard to make a recommendation without knowing more about what you are trying to achieve.
Please update frame in -(void) viewWillAppear method as in viewDidAppear your view is practically set and is ready to displayed.
after updating your button's frame please use following line of code
[self.view laoutIfNeeded];
Thanks
Hi I have set in my storyboard a UIScrollView (of the same size of the view) and ctrl-dragged it in my code.
Now I have created a button programmatically using a simple algorithm of mine.
I then tried to
println(button.frame.origin.y)
which printed 1700.
Then I tried
println(button.frame.height)
which printed 142.2 (also coming from the algorithm). So the heigh I would like to reach while scrolling is 1700 + 142.2 = 1842.2
So i tried to hardcode the content size in this way
self.scrollView.contentSize = CGSize(width:self.view.bounds.size.width, height:2000)
But when I run the app I can scroll no more than the middle of the button, which is in numbers
1700 + 142.2/2 = 1771.1
Why the heck is that?
I did all this to try to understand how this UIScrollView works but I can't figure it out.
EDIT
Added a screenshot.
Inside the bubbles there is the button.frame.origin.y value. That's the max I can scroll leaving the screen untouched.
This is probably to do with scroll view insets - a mechanism where the edges of the content always appear under the navigation and toolbar.
You either need to manually account for this by reading the contentInset property of the scroll view, or using interface builder.
Scroll view Reference:
https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/UIScrollView_pg/CreatingBasicScrollViews/CreatingBasicScrollViews.html
I have a single scrollview in my view controller and several subviews (textfields and labels). These subviews appear grouped in the middle of the screen, although I added constraints.
How can I make them appear with the standard spacing to the navigationbar?
It might be a problem with translucent nav bar.
Turn on the nav bar translucent and see if the views are correctly positioned. If they are, you have to adjust the spacing in IB.
Autolayout doesn't work the same way as everywhere else when inside a scrollview--it's a whole new ballgame (as described in apple's documentation).
If you place a UIView within the UIScrollView, and make sure you have that view the same size as the scrollview's content, you can use autolayout in this new view to place all your textfields/labels however you like.
For more info, see apple's docs on scrollviews & autolayout.
setting
self.automaticallyAdjustsScrollViewInsets = NO;
or, alternatively and corresponding in the storyboard, did fix it for iOS7. Don't know if this works for iOS 6
I'm pretty new to ios. I'm working on a project which is going to frequently use a certain UIView class throughout the application. This class is simply an image that does some transparency stuff with the background color. This works fine so far. This class sometimes exists as a lone UIView, and sometimes as a button subview.
When I add this UIView to a UIButton as a subview, the full contents of the UIView are displayed at full size, but the clickable area of the button remains the size defined in the xib unless Use Autolayout is turned off (even if I manually try to set the button's frame.)
I would like to put a UIButton on the xib as a placeholder, and then later define its size/clickable area based on the size of the overlay image which the UIView that was initialized with.
Should this be possible, or am I misinterpreting the usage of xib files/autolayout?
under ViewDidLoad I have...
- (void)viewDidLoad{
[theButton addSubview:_theView];
CGRect buttonFrame = theButton.frame;
buttonFrame.size = CGSizeMake(_theView.getSize.width,_theView.getSize.height);
[theButton setFrame:buttonFrame];
}
However, the frame stays the same size when I print the button info before and after I try calling setFrame.
(note that '_theView.getSize' was added by me)
Under Autolayout, views don't have frames at viewDidLoad. Try your code in viewWillAppear: or viewDidLayoutSubviews.
Under Autolayout, you don't set frames. You edit constraints instead. Setting a frame will work until the next layout pass, when your layout will revert to that described by your constraints.
To size a button to fit a subview, you can try something like this (in visual format language): |-[theView]-| but it would depend what constraints are in place from your xib.