I have specified a custom cell containing a label and a text field in a nib file.
When I change the text property of the label and adding three of those cells in a section of a table view it looks like this:
When I don't touch the text property and simply adding the cell out of the nib file "as is" it looks like this
Well there still remains the question why the textfields right edge moved, but that is not the main problem. Can somebody tell me how I have to configure the label to avoid that nasty behavior when changing the labels text?
Change the frame of your UILabels. Now it looks like they are about 280-300px wide. Change it to something less, 120 for example.
yourTextField.frame = CGRectMake(0, 0, 120, 30);
or some other numbers. Play with it.
Hope it helps
P.S. some code would be nice
Aaaah the great mysteries of autoresizingMask. Do it like this:
Resize your labels width and can always change label background to clear
yourLabel.backgroundColor=[UIColor clearColor];
Related
I'm trying to make (using Visual Basic) a rudimentary questionnaire that measures multiple attributes and stores their values in an array and afterwards measures the attributes on a scale of 1 to 10.Now I've had the dumb idea to use a label for every single value of every attribute, and highlighting the right number by changing the label's image to yellow, instead of white(basically making the area behind the number a different color).
Now here's the issue: I can't seem to find out how to change a label's background image with code, which is what I'm asking. (I'm guessing the command should look something like "Label1.image = >image path<")
Pretty simple.
If text = No then
Label.Text = No
Else
Label.Text = Yes
End IF
You just have to change the text value of the label which is .Text = Text you want
And if your trying to show images, you should use the image control in the tool box, not a label
I'm trying to insert an UIView on the left of a UITableViewCell, but when I do that I don't know how to move/indent the whole cell to avoid overlaying the View.
If I use
cell.indentationLevel = 10;
Only the TEXT will be aligned, not the whole cell.
IE: http://i463.photobucket.com/albums/qq357/darkCB666/iOSSimulatorScreenshot19032014000530_zps44572bfa.png
I'm trying to do somehing like WhatsApp and Facebook Chat contact list (the cell lines are aligned with the text).
Try setting the separatorInset property instead, like this:
cell.seperatorInset = UIEdgeInsetsMake(0, 10, 0, 0);
That will inset the line and automatically adjust the default subviews along with it.
A common trick I've seen and used is to just lay out the cell with my own line to achieve the look I want. Rather than use the iOS default line, insert your own line at the position and length you need to account for the left-hand UIView.
I am using master/detail template in Xcode. I can add text into the maintitle and the subtitle of the table view.
The subtitle only shows one line of text with ... at the end.
I understand that it is telling me that more text is available.
How would I have it give me 2 or maybe 3 lines of text before the ... I tried making the cell larger, but that had no affect.
I don't see any parameters that will increase the number of lines.
thanks
The default cell give you a label with just one line, if you want change it you will need to create your own custom UITableViewCell and add a label wit the number of lines you need:
Customizing UITableViewCells
I have a two line UILabel. I want its line break mode NSLineBreakByTruncatingMiddle. The problem i am getting is if text is small enough to fit in one line, its showing it in middle of label instead of at top. I am using iOS6 and autolayout so sizeToFit is not working for me.
How can i achieve this? I want if text is small to fit one line it should be vertically top aligned. I have tried this, but its truncating and showing the text in one line only rather than two line.
You need to calculate the required size and update the frame of your label:
CGSize s = [myLabelString sizeWithFont:...
constrainedToSize:CGSizeMake(..., MAXFLOAT)
lineBreakMode:NSLineBreakByTruncatingMiddle];
With whatever font your label is using and its width.
I'm creating a label dynamically, and then adding text to it dynamically (and the amount of text added to it will be different each time). So, the label needs to always be the same width as the text inside it.
This happens by default when creating a label in the Windows Designer. But when creating a label dynamically, it appears to be "set" at a specific width, regardless of how much text is in it (which means that it often "cuts off" some of the text).
So... any idea how I can get the dynamically created label to always stay the same width as the text inside it?
If you want to do it manually, you can do something like this, every time you change the text:
Dim g As Graphics = Label1.CreateGraphics()
Label1.Width = CInt(g.MeasureString(Label1.Text, Label1.Font).Width)
However, it's much easier to simply set the label's AutoSize property to True and let the label do the work for you.
Label1.AutoSize = True