how to know tableview size xcode iphone? - iphone

- (double) tableSize
{
double tableSize1=[self tableView:tableViewA numberOfRowsInSection:0]*tableViewA.rowHeight;
return tableSize1;
}
I use that code to know tablesize, but I want to know easier way to know it.. like tableviewA.size or something like that..
example : tableviewA have 20 tableviewcell, I want to know the tableviewA size.. how to know it?
If I do tableViewA.frame.size.height it'll always show 400, which is the height of the table frame, because that's the size of the table view. I want the size of the whole table including those I need to scroll. –
For example, if the tableviewA has lots of rows then I want to see a high number

You can use this - tableView.contentSize.height

this help?
tableView.frame.size.height
or
tableView.frame.size.width
then may be you can use
CGSize tableViewContentSize = tableView.contentSize;
to get the content size.
then to get the height and width just
tableViewContentSize.height
tableViewContentSize.width

Related

increase height of a specific row

Initially, all rows will have the same height of 50. When a cell is focused,if it has more content and requires more height, I need to increase the height of that particular cell. If that is not possible, atleast that entire particular row's height has to be increased. The remaining rows should not get effected.
I would make use of rowSelection api particularly the selected property of each rowNode.
You can define getRowHeight in html [getRowHeight]="getRowHeight"
and (selectionChanged)="onSelectionChanged($event)"
And define getRowHeight like this -
this.getRowHeight = function(params) {
return params.node.selected ? 100 : 50; // if selected height is 100 else default 50
}
and then in your onSelectionChanged,
onSelectionChanged() {
this.gridApi.resetRowHeights();
}
The reason you would want to piggyback on selected attribute is because it is maintained by ag-grid for each row.
You could do something similar by implementing the callback onCellFocused but then you will have to maintain a similar attribute for each row because you also need to adjust the height once the focused row is out of focus which might be an expensive operation.

How to use the full width when an UI element is invisible in iphone?

I have a label and a button like in the above picture. I like the label to use full width when I click on hide button.
I tried setting the width to 0, how ever it does not change the label with. Is this correct? or is there a better way to do this ?
blockingButton.frame = CGRectMake(blockingButton.frame.origin.x, blockingButton.frame.origin.y, 0, blockingButton.frame.height)
No, 0 can cause problems.
Try this:
blockingButton.frame = CGRectMake(blockingButton.frame.origin.x, blockingButton.frame.origin.y, self.view.frame.size.width, blockingButton.frame.height)

Relative UILabel in a game object

I created a game object which acts as a repeating item for a UIGrid which I populate dynamically. The gameobject (RowItem) has couple of UILabel whose text can change on runtime depending on the content. The content of these UILabels overlap when the text is bigger. Can anybody help me in how to make UILabel expand relative to the adjacent UILabel when the text is more/less?
You can use transform.localScale property of the UILabel's property to scale it. Just make them bigger when the text is bigger than let's say 20 characters. Try with arbitrary values.
Also when you change the scale, run a re-align method, which aligns other labels so that they don't overlap.
you can get the text length in pixel by this:
UILabel label;
float width = label.relativeSize.x * label.transform.localScale.x;
float height = label.relativeSize.y * label.transform.localScale.y;
Let's say that you want to set you max length to 100, you can do this:
if (width > 100)
{
label.localScale = new Vector3(100 / label.relativeSize.x, 100/ label.relativeSize.x, 1);
}
the second param for Vector3 is also based on relativeSize.x is not a typo, that makes sure your text will not become thin.
Hope this works.

How to count line breaks (not /n) in an UITextView?

I would like to count how many automatic line breaks (not returns the user enters) I have in a text displayed in UITextView which is, for argument's sake, 200 pixels in width and 460 pixels in length (see attached screen shot!).
I have found this when looking for a solution:
stringSize = [t sizeWithFont:f constrainedToSize:CGSizeMake(320, 10000)
lineBreakMode:UILineBreakModeWordWrap];
But this won't give me an int number for 'invisible' line brakes, will it? Also, I don't understand the 320, 10000 ... 320 is for the width I guess and would need to be changed to 200 in my case. But why 10.000 ??
Sorry, but I'm a beginner and this doesn't make much sense to me...
The CGSizeMake statement is to provide bounds in order to compute the size of text. It is common to constrain the width and to set a high value for the height to let enough space for the computation.
In your case, the width will be 200 and you can leave the height to 10000 as long as the text is not too long.

Split String at specific line for NSString

Hello ist there a way to split a String for UITableView at a specific line to put the "rest" (the second part of the data) in an own cell
NSString *data;
CGsize *size = [data sizeOfStringWithFont:[UIFont systemFontOfSize:14] constrainToWidth:280.0];
if the size.height e.g. is greater than 1500 i want to split the string at this line position!
thank you
Use "constrainedToSize" (instead of just to width) and render as much as you can.
If you really want to take exactly the text that would not fit, you're going to have to do essentially a search, adding a word at a time and then doing the size check to see how high you have gotten. You could start out with a rough estimate by doing the whole string constrained to something only one line high with boundless width (say 999999) and then divide up the width into however many rows you are wishing to allow to get a rough starting point for adding/removing words from the string (it will not be exact because of word wrapping).
Fundamentally though it seems wierd to take the leftover text and put it in another cell. Are you really sure you don't simply want to change the height of the cell with the text to allow it to fit the whole thing?
I think Kendall has the right idea, but the constrained sizes should be reversed to get the exact height based on word wrapping. Take a sample CGSize that is the same width as your cell, but with a height larger than the max height you expect. In the sample code below, textSize will contain the height of your string as it would appear in your cell with an unbounded height.
CGSize sz = CGSizeMake (
yourCellWidth,
999999.0f );
CGSize textSize = [yourString sizeWithFont:yourCellfont
constrainedToSize:sz
lineBreakMode:UILineBreakModeWordWrap];
If the height is greater than 1500, you could start picking off substrings (substringWithRange) from the end and measuring them like above until you get something >= the remainder above 1500 that was returned by textSize.