I have created a table view with prototype cells in a Storyboard with the "Use Autolayout" unchecked in Xcode 5.
The cells are UITableViewCell subclasses, mainly to add IBOutlets and no code inside. The result is a messed layout. I tried changing the Autoresizing masks with no luck. Also tried this.
If I however implement an empty layoutSubviews it shows ok. Any idea of what's going on?
Is auto layout still enabled despite unchecking it?
Edit:
More details...
#interface SettingDefaultTableViewCell : UITableViewCell
#property (nonatomic, weak) IBOutlet UILabel *label;
#property (nonatomic, weak) IBOutlet UIImageView *imageView;
#property (nonatomic, weak) IBOutlet UIView *backgroundView;
#end
#implementation SettingDefaultTableViewCell
- (void)layoutSubviews
{
// Emtpy implementation to fix weird layout bug
}
#end
Storyboard with Autolayout disabled:
Result when layoutSubviews fix above is not used:
Edit 2:
The cell is set to not autoresize subviews.
While the above should be enough to prevent subviews from getting auto-adjusted, also all autoresizing masks are set to flexible right and bottom margin only.
Only the > mark is set to flexible left margin. No flexible width or height.
The cell is getting modified by the undocumented UITableViewCell's layoutSubviews:
Despite set not no autoresize subviews, the default implementation changes the backgroundView frame.
It also moves imageView (the ">") to the left despite being configured as a Custom Style cell.
Thus avoiding executing super's layoutSubviews fixes it.
Related
I am using UIScrollview and top of a UIView but scrolling is not working.
for scrollview i added constraints all the side (0,0,0,0) then i have take container view and adedd constraints for (0,0,0,0) for all side . and one more constraints i added for this container view to View with equal width.
my scrollview hight is 504 and containner hight is 840. i am not getting any warning and suggestion constraints but not able to scroll . what is missing here .Please suggest me .
if you have added constraints properly . then add this
make property or your scrolview and container view as
#property (weak, nonatomic) IBOutlet UIScrollView *scrollview;
#property (weak, nonatomic) IBOutlet UIView *containerview;
then in .m file
#synthesize scrollview,containerview,
then add this
-(void)viewDidAppear:(BOOL)animated
{
[scrollview setContentSize:CGSizeMake(scrollview.frame.size.width, containerview.frame.size.height)];
}
I hope the will solve your issue.
There is no problem with autolayout in x-code 6.4 just try to check that you have properly bind the outlets of scrollview as well as give contentsize to scrollview that how much you would like to scroll your scrollview.
scrollview.ContentSize = CGContentSize(0, height);
--> Give height as float or integer as how much you want to scroll your scrollview.
For the ScrollView to work, reference it to your .h file by CTRL + Dragging the scroll view, and on your .m file add a
scrollView.contentSize(0,doubleTheSizeOfTheViewHeight);
if you want the scroll to be scrollable horizontally do the same with the width.
Hope this helps
Update
Or you can always use this for the storyboard way of doing it:
Storyboard UIScrollView contentSize?
To make UIScrollview scrolling, you have to uncheck checkbox with "Use Auto Layout" from XIB.
I place a UIProgressView on an XIB file. At first it goes well. After when I set its height via auto layout to be 20, problem occurred. The Progress View always got its position at the most top-left of the screen. even I use
[self.progress setFrame:CGRectMake(93, 100, self.scrollView.frame.size.width, self.scrollView.frame.size.height)];
still don't work for me at all.
Thank you very much for any help.
use size constraints as outlets. Then you can easy change values of those constraints. It's not really recommended to modify frame when using auto-layout.
declare a property:
#property (strong, nonatomic) IBOutlet NSLayoutConstraint *heightConstraint;
#property (strong, nonatomic) IBOutlet NSLayoutConstraint *widthConstraint;
and in the implementation:
self.heightConstraint = self.scrollView.frame.size.height;
self.widthConstraint= self.scrollView.frame.size.width;
Alternatively you can try to set frame in viewDidLayoutSubviews but it's not recommended when using auto-layout.
I am designed my screen in xib using autolayout(xcode 6). I have to redesign the screen programmatically using autolayout.
I have 4 views in my screen horizontally. I have to hide the third view and move the fourth view to third view's position using autolayout.
How do I update the constraint programmatically.
You may use NSLayoutConstraint and assign proper IBOutlet to any of your constraints and then where you wants to change the view size use constant property of NSLayoutConstraint to change the value.
e.g
in your viewController.h
#property (strong, nonatomic) IBOutlet NSLayoutConstraint *tempConstraint;
some where in your viewController.m
tempConstraint.constant = 50; // or what ever you want
I have a UIViewController with a UITableView set in interface builder.
In my h-file, I have connected the UITableView *myTableView.
(#property (strong, nonatomic) IBOutlet UITableView *tableView;)
In the bottom of my view, I have a toolbar. This toolbar covers the last cell of myTableView.
After reading around a lot, I find that I can set the height this way:
CGRect fr= CGRectMake(0, 0, myWidht, myHeight);
[self.myTableView setFrame:fr];
NSLog(#"test %f",self.myTableView.frame.size.height);
This logs : test "myHeight", but myTableView is still covered by the toolbar!!!
I have also tried to set the constraints in interface builder, but I still fail.
Is there a way to fix this issue, so the last cell in the tableview is not covered by the toolbar in the bottom of the view?
Resetting the simulator, and adjusting constraints in interfacebulder solved it :-)
Came up this question and did some quick experiments without no luck.
Basically, I made a simple single view project where the top view controller is a UITableViewController. For simplicity, I set the table view content to be "Static Cells". The table cell was a custom subclass of UITableViewCell, like this
#interface TopTableViewCell : UITableViewCell
#property (strong, nonatomic) IBOutlet UILabel *label;
#property (strong, nonatomic) IBOutlet TableCellBottomView *bottomView;
#end
Both the properties were wired through control dragging. The TableCellBottomView is just a custom subclass of UIView like this
#interface TableCellBottomView : UIView
#end
Now I add a label inside this TableCellBottomView like the following picture showing
Can I wire this bottom label inside to my TableCellBottomView? Control dragging did not work for me here. I certainly could have added it programmatically inside TableCellBottomView.m. But if i could wire it here, it would be quite convenient, since I could also add a lot of other components and arrange them visually. Thanks!
You may set a tag for the label in Xcode and fetch the UILabel based on the tag wherever you need it:
If you use dynamic cells, you can do this in tableView:cellForRowAtIndexPath:. Alternatively wire the cell to a property and then use that property to fetch it:
((UILabel*)[cell viewWithTag:1]).text = #"Some text";
I don't know why Xcode won't allow you to drag from your label to the bottom view .h file, but you can do it another way. Add the IBOutlet property to the .h file, then drag from the littler open circle to the left of the #property to your label in the storyboard, and that should work.