Aligning rows in UITableView - iphone

This may sound a newbie question, however I'm new to iOS dev.
I've got a UITableView on my iPad app. TableView has obly three rows, is there a way to tell UITableView to view rows vertically centered, i.e. to not from the top to down.

Figure out the sum of the heights of all 3 rows, call it MyTotalHeight.
float MyTotalHeight = heightOfRow0 + heightOfRow1 + heightOfRow2;
Set your
tableView.frame = CGRectMake(start_X, start_Y, tableWidth, MyTotalHeight);
If you want the contents of each row/cell to be centered vertically within the cell, this will depend greatly on what is in the cell. You will need to calculate the height of the content and then center that content vertically within the cell by adjusting it's frame.

You may want to try the UiTableView.sectionHeaderHeight property. Play with the number until the cells are centered vertically. If your using a plain table view, I don't know how well this will work for you.
--John

Related

Random table view cell height is not working perfectly

I am designing a chat app in which I am using the UITableViewAutomaticDimension property of table view when I am setting the label lines to 6 then all cells height is according to the text which label contains but when I increase the number of lines for label then some cells have extra height. Even when scrolling it then cell height again changed.You can check the image so that you can understand it easily thanks.
You need to give label constraints from top and bottom, rather than center vertically.
Give vertical content hugging priority

Show a label over the limits of a UITableViewCell

I'd like to use a UItableView to show a day Calendar. Each row corresponds to one hour. I need to show the hour between 2 cell of my tableview.
Like this :
(source: free.fr)
And this is my UITableViewCell :
(source: free.fr)
In the first screenshot, it works perfectly but if I scroll down then scroll up, my time label is cut like this :
(source: free.fr)
Have you any tips to figure out this problem using a tableView ?
The way you lay out your cell now is fragile, because the order of painting the cells on screen matters a lot. Try moving the content up so that your buttons are flush with the top of the cell, and the time label fits into the cell entirely. Add a thin header view to your table to make the top cell appear normal. Keeping the content of a cell entirely within its bounds should help you maintain reasonable scrolling speeds.
EDIT : You could also put a second clipped label at the top of your cell, and make its content identical to that of the label in the prior row. You would need to take special care to hide that label in the top row, but otherwise this should make your table immune to changes in the rendering order of its cells.
Make the background color of your cell clear. As you scroll up the z ordering of your cells get reversed and the lower cells overlap the higher ones causing this clipping.

UITableView scroll both vertically and horizontally

I have too many columns in my table and too much data too. For that reason I need to scroll my UITableView both vertically and horizontally. Is there a direct way to do so or I need to go through sources like Easy tables?
You can use an UIScrollView and then inside add the UITableView. This UIScrollView will have the same size that your UITableView have now, but the UIScrollView contentSize property will have the same height but it would have a greater width.
I have a similar situation: a lot of columns and rows, the tableView needs to be horizontally scrollable. My solution is like that:
predefine a column header with width same as the desired tableView, say 537
top view (320 x 455)
+ scroll view (320x455), content size = (537x455)
+ view as a container (537 x 455)
+ column header (0, 0, 537, 44)
+ tableView (0, 44, 537, 455-44)
Create a function to compute these numbers and reattach the frames to each object
after tableview reload, call this function
Here is a trick to do both vertical and horizontal scrolling with a UITableView.
Playing with width and contentsize to make it work:
https://stackoverflow.com/a/41230797/860488

Height of UIPicker

I've been trying to change the height of a pickerView. I would like it to show a single row instead of the default five rows.
help me plz
Better u can use PickerView Frame like this,
Pickerview.frame = CGRectMake(30,100,170,200);
You can't. UIPickerView can show either 5 rows or 3 rows, depending on the height of the frame you pass to the -setFrame: method. When I need a short UIPickerView, I'll pass a height of 100. The code in UIKit will adjust that height to be the closest allowed value.
I'll also note that this is for a very good reason. A one row pickerView, as has been noted elsewhere, would be fiendishly difficult to scroll. Also, the number of visible rows must be odd so that the currently selected row will be centered vertically. This means 3 or 5 rows, because 7 would make the thing way too tall to be practical on an iPhone.
As an aside, this also works with UIDatePicker for the same reasons. The exception is when the date picker is in the UIDatePickerModeCountDownTimer, which does not support the 3-row variant.
If you absolutely MUST have a one row picker view:
Create a UIView sized 170 wide by 55 tall.
Set the view properties clip subviews = YES
Add a UIPickerView as a subview of the UIView. Set its origin to 0, -80.5.
Then add a UIImageView sized 170, 55 as a subview to the UIView. Set its image to the one shown below.
(You can modify the image and make it stretchable to resize it horizontally)
Final Result:
did you try to implement numberOfRowsInComponent: ? If this doesn't change the size, did you try to set the picker's frame ?
ps: I agree with #Ritheesh#BoltClock, one row isn't a good idea

Clipping within an UIView with some subviews

I have some buttons in an UIView. My problem is, that they get cut
off at the right side of the UIView. How do I prevent this?
alt text http://img.skitch.com/20090629-mj32p1bkff476256pwrpt69n2d.png
I've checked already Interface Builders clip property, but it's no
solution for this problem.
Regards
It seems like either you made these buttons programmatically, or you reiszed the initial IB view window to be larger and expected it to shrink down to the fit the screen.
The buttons in question cannot fit on the screen as they are - what effect are you looking for?
If you want the buttons all to fit you could set the text size to be smaller, and then they could fit.
If you want the buttons the size they are then you'll have to make another row, or put the buttons into a side scrolling container.
I have been using java and only recently began learning Apple's Obj-C framework.
An alternative to scrolling and row-breaking is using a "grid" layout with 1 row and n columns, where n is the number of buttons. Each cell has a fixed size. And you will have to resize your buttons (the subviews) in your superview's setNeedsLayout: method to whatever width you need such that all buttons fit the row.
See java's GridLayout class.
Kendall, thanks for your answer.
Here is my solution:
if(previousFrame.origin.x + theStringSize.width > 220){
roundedButton.frame = CGRectMake(15, previousFrame.origin.y + 30 , theStringSize.width + 8, theStringSize.height);
[myContainer insertSubview:roundedButton belowSubview:[tagsContainer.subviews lastObject]];
}else {
roundedButton.frame = CGRectMake(previousFrame.origin.x + previousFrame.size.width + 5, previousFrame.origin.y, theStringSize.width + 5, theStringSize.height);
[myContainer insertSubview:roundedButton belowSubview:[tagsContainer.subviews lastObject]];
}
I calculate, how many pixel I've moved from the left side. At some threshold (in my case 220) I start a new line.