I am trying to fit a button to the bounds of a grouped table cell. As you may know, grouped table views have margins along the left and the right of the cells. However, the bounds of the cell are as if those margins did not exist. I COULD hard code the frame but I was curious as to if there was a better way to fit a button inside the cell bounds of a grouped table.
here is my current set up... I also read in another post here to try the autoresizing mask, but that didnt work either.
SubmitButton *search = tableValues.key; //pulling my button object from an array
search.frame = cell.bounds;
cell.clipsToBounds=YES;
[cell addSubview:search];
with this, the edges of the button still stretch beyond the margins of the cell.
Thanks
Subviews should be added to a cell's contentView, not directly to the cell. The cell's frame is the full width of the table view, even with grouped tables. The cell's contentView is sized properly to take into account plain vs. grouped as well as various cell decorations like delete icon, reorder handles, and disclosure indicators.
Adjust the button's frame to the contentView and add the button to the contentView.
Related
I'm beginner with collection view,
I need to create cell like this
Can I do it from Storyboard?
I want to add margin of cell = 4 or 5 in the top, bottom, lift and right in iPhones and iPads of all sizes, or I if need to do that programmatically How I can add the contents of the cell like the image above?
There is no "margin" here. There is simply a rectangle with a shadow, and everything else is drawn in front of it. The simplest solution is probably a custom UIView that draws itself as a rectangle with a shadow. Make that the content view's direct subview, and everything else in the cell is a subview of that. The inset of the rectangle-with-shadow within the cell's content view can be determined by autolayout (and the position of all the stuff inside it can be determined by autolayout too).
Thus it was trivial for me to obtain this sort of thing:
And of course you can tweak the border color, the background color, and so forth.
I have a UIVIew on which I loaded a UITableView as subview. The tableView is exactly the height of all it's rows(4 of them) heights sumised, about half the height of the main view.
The problem is that when I drag a row to move it I am able to drag beyond the bounds of the table and this cuts my cell's view (I am only able to see the part that is still in the table's bounds).
Is there a property I can change to stop the cell from being dragable out of the table's bounds?
you can do this like below..
[yourtableview setBounces:NO];
let me know it is working or not!!!!
Happy Coding!!!
If the UITableView is exactly the height of the 4 rows . Then you Do Not Need the Scrolling functionality of the UITableView and you can simply stop the scrolling by :-
TableView.scrollEnabled = NO;
Hope this is what you wanted . Please tell otherwise.
I have an array which loads in a database depending on what button the user chooses. How can I add these buttons to a scroll view which is only as large as it needs to be to hold all the buttons? I know I can declare the size of the scroll view, but I don't want it to be too large so that it can fit a large number of buttons then have lots of empty space if a smaller array is used to create less buttons. Is there an easy way to do this?
I assume you can figure out the vertical height required to display the number of buttons to be displayed before adding them to the scrollview.
If so, at the time of adding a fresh set of buttons, or 'refreshing' the scrollview, I guess you can simply set the correct contentSize of the scrollview.
Check the UIScrollView reference for #property(nonatomic) CGSize contentSize
You can do it in two ways .
Either you can change the frame of the scrollview dynamically
myScrollView.frame = CGRectMake(x, y, newWidth, newHeight);
or you can change the contentSize of the scrollView dynamically keeping the frame constant.
myScrollView.contentSize = CGSizeMake(newWidth, newHeight);
I am working on an app that has TableViewCells with varying heights. I am placing a UIImageView into them and each will use the same size image (the same size of the largest cell), however I need to mask the excess in the smaller cells (keeping the bottom, not the top).
To be more specific, I have 3 different cell heights, 112, 104 and 88. The images will all be 112 tall and I want the images to have the tops cut off on the smaller cells. Im pretty sure the answer lies within the bounds, frame and center attributes of a UIImageView, but I cant figure out exactly what I should be doing.
You will need to set the frame of your image view such that the bottom of the image view is aligned with the bottom of your cell.
You will also need to ensure the contentview of you cell is clipping content to its bounds (setClipToBounds to yes).
If I had to do this I would subclass the UITabelViewCell class and implement the layoutSubviews method. In your implementation don't forget to call super first so the content view has the right size (also if you go in editing mode). Then use the content view bounds and place your content accordingly.
When you add the image view to the cell, it should automatically cut off the top part, as long as you have the UIImageView bottom positioned within the frame, it should be what you wanted.
The design of the UITableView is something like this:
I want to make my cells with a tiny triangle, like in a comic book. The thing is, how can i add the triangle to the size of my custom cell? The common rectangle size wouldn't work if i want the user to be able to tap that little rectangle.
And how can i make the opposite? I want the triangle to cover the space of another cell, so tapping the little triangle of the first cell, covering part of the second cell's rectangle space, would activate de first one. This is, substracting a little triangle from the cell's space.
Not sure it would work, but building on user697562's comment, you could try the following:
Add a small UIView to the table cell to represent the small triangle
Rotate it using its transform property, making sure that, along with its frame, it will have the proper placement.
Add a UITapGestureRecognizer to the UIView
Add an instance variable to the view to save the indexPath of the cell it's in (or even the above cell, since it will be associated with the above cell). This way when the gesture recognizer is triggered, you know what row you're in.
Write the action method associated with the gesture recognizer to do the same thing as tableView:didSelectRowAtIndexPath: would do for the above cell.
Set the separatorStyle property of the UITableView to UISeparatorStyleNone, so that it won't draw the lines between cells. If this doesn't work just set the separatorColor property to your table cell's background color.
Draw a border along the top & bottom of the cell, accounting for the triangle.
Good luck with it! Let me know whether it works if you try it.