nstableview how to fit text - swift

The problem is to fit text into cell. With cell.textfield.sizetofit() and layouts I can create text on more than 1 line, but visible is only one
if I make text size small I can see second line but cut by half

Related

Vertical Align Crystal Report Text Filed

I have a scenario in which my reports fields doesn't look like centered Vertically,
Below is the screen Short of the output.
As it can bee seen from output that data with a bigger font is clearly seen centered vertically, but the data pointed with lines is left-top justified, i want that to be left-centered.
For vertical alignment I did this .
and code behind formula is:
if {NewReport;1.TireLevel} = 1
then
crCenteredHorizontally
else
crLeftAligned
The Editor Screen.
Sadly, Crystal Reports doesn't support vertical alignment in the same way it supports horizontal.
It's possible to use labels on the vertical ruler and enforce Snap to Grid, but that might not work within a table. Or you can add line breaks, blank rows, or plain white objects to push things into position. But there's no easy way to enforce a vertical center.
In your particular case, I would actually make two seperate fields: One for large text and one for small text. Layer them on top of each other and reuse your current formula to alternate their suppression. This way you can move the smaller text vertically down without undoing the vertical alignment on the large text field.

Text in textview is not vertically centered

I'm trying to create a text view which height follows number of line in it. I've worked on constraint but here I've a curious issue :
At the beginning all is centered as I want
When there is a break, text is not vertically centered anymore and goes in top left corner
When you delete characters and then come back to previous line, the text is yet vertically centered
Here is the code
func textViewDidChange(textView: UITextView) { //Handle the text changes here
if(textView.text != ""){
self.animateSendButton(true)
}else{
self.animateSendButton(false)
}//the textView parameter is the textView where text was changed
heightTextfieldConstraint.constant = self.textField.contentSize.height + 2
textField.contentInset.top = 1
}
I don't understand why there are these 3 different cases, do you have any idea to solve it ?
You can try and add an inset to the top, bot, left and right, that should keep the text centered even after a second line appears.
textView.textContainerInset = UIEdgeInsetsMake(5, 5, 5, 5)
You might be better off keeping the text view itself vertically centered while ensuring that the text view is always sized to fit the content. You can do this with Auto Layout.
Set the text view to be vertically centered in its container and also add a height constraint to the text view with a low constant value (about the height of 1 line of text). Then set the text view's Content Compression Resistant Priority to a value that is higher than the text view's height constraint (see screenshots).
I've done it in "Main.storyboard" of this demo project of mine if you want to see a working example:
https://github.com/patricklynch/Walkthrough
Perhaps you could call view.layoutIfNeeded() after text has been entered.

Why does the Label text not always start from the same point?

I have a UILabel which has 4 lines. Its font size is 15 & autoshrink is enabled. It's minimum font size is 10.
When my text is too long then it automatically starts from first line. But when my text is too small then it starts from middle line.
How can I make sure the text always starts from first line, whether it's too long or too short?
I think what you're looking for is more a UITextView than a UILabel.
From Apple's doc :
UITextView displays a region that can contain multiple lines of editable text.
The editable part is optional. You can disable it, along with scrolling if you want to be close to a UILabel.

Creating a fixed formatted cell in UITableview

I want to have a tableview create rows that look like this:
value1 item1 container1
value10 item10 container10
value100 item100 container100
value2 item2 container2
What I am trying to show is that the first word (value) will have a set length of 12 and then the second word (item) will have a set length of 10 and then the last word (container) is just tagged on at the end.
I am pulling these from a SQLite database and don't want to use multiple lines, but read in a strictly formatted structure like this.
You can layout a custom UITableViewCell in Interface Builder, where you drag two UILabel views onto the Content View and set their size appropriately (Notice that the letters may vary in width, so even though you know it's 10 chars in length, you don't know the maximum width, please keep that in mind)
Then you just fill the open space at the right of a cell with another UILabel, layout it to cover the open space and set it to autoresize it's width and set the right margin to be fixed.
There are quite a few tutorials available on how to use the custom cell in your tableView, I can recommend you this screencast. It explains how you can initialize the custom cell and how you can access the custom labels.
It sounds like you want something like an old-fashion text display in which then nth character in row zero always lines up the nth character in every row.
Even using carefully positioned labels in a custom tableviewcell, you will have to strictly control the specific font and its size if you want all the characters to line up in fixed width column. You will need a fixed width font to begin with and you will have to set the size precisely.
You might want to consider whether this is necessary. iPhone users are used to propionate width text displays. Very precise columns of text might make it difficult to discern rows. I would test first with just a simple table before spending the time tweaking the columns.

Break a text in a label in iphone

I am new to iphone development.I have created three labels in a cell and i have just displayed the text in the corresponding labels , but i want to display the full text in the label.I am not able to see the full text,So is there any possibility for breaking the text and show them in two lines.I am not displaying any static text .I am getting the text dynamically from the website and displaying it in the label.Please help me out.Thanks.
set label's numberOfLines property to 2 (or to 0 to have any number of lines you need)
set label's lineBreakMode property (e.g. to UILineBreakModeWordWrap)
make sure that label's height is enough to contain 2 (or more) lines of text