I have a simple login form on a TTTableView, in which I use TTTableControlItem with UITextFields.
I have two fields, Email & Password. Since the UILabel's width determined by the text, the two textfields aren't aligned vertically to the same line and it looks bad.
How do I control the width of the caption inside?
Is there another way to achieve this without subclassing/finding the labels/controls and move them after render?
Thanks.
You'll have to subclass TTTableControlCell with your own custom cell and override the function
- (void)layoutSubviews;
to layout the contents the way you want to.
Also don't forget to map TTTableControlItem to your new custom cell subclass in your data source (in the
- (Class)tableView:(UITableView*)tableView cellClassForObject:(id) object;
method)
I had the same problem and I chose to just set the text field to align the text on the right. I didn't like the amount of padding so I modified TTTableControlCell to cut back the width of the text field.
Related
In my project, I have three types of custom UITableViewCells. One for text-only, one for text + url and one for text + image. I am using auto-layout with IOS 8.0 and am trying to use constraints to make the text block only appear if not null. The text being before url and image I don't want to get an extra useless space.
Is it the right way to go or should I implement two new types for image-only and url-only?
I have been trying to set up height >= 0 for the text block in the constraints but it keeps be displayed.
If you don't want the text view to take up space, remove it from the cell for that row. Of course, for rows where the text view is needed, if it is absent, you will have to add it. Making the constraints correct will also be up to you.
I wonder what ui element I should use for large sets of text. Eg anything between 200 - 1000 characters.
I already place the text inside a scrollview so it doesn't have to ve scrollable or editable etc, I just want to display text.
So what should I use between label / text view / text field?
Thanks in advance.
Text views are good for texts with varying lengths, but they have a scroll view of their own. You may consider using a normal UILabel and setting the "Lines" property to 0. I know that sounds strange, but setting it to 0 tells the label that it is a multi-line label. Then you can use auto layout to establish the width of the UILabel. It will grow down based on the amount of text in it. Text fields would be inappropriate for displaying texts in most cases; they are better for user input.
I have a textfield in a tableview 's last cell. The textfield is one line at beginning, when I input some text more than one line, I need the textfield change its height for me can view all text. How can I do this?
edit 1:
I have try text view, it can input multiple line text, but how can I know when it from one line become two line? because I need resize cell height also.
edit 1 's answer
UITextView Auto Height
You can't do something like this with a UITextField because it's intended to be only a field and you can't change its height. Otherwise take a look to UITextView which can be set as you want, its frame etc... You only have to set it as editable so you can write text in it.
I have been recently getting into iOS development, and I'm trying to build something that looks (very roughly) like this: http://falkendev.com/downloads/ios-sample.png
Basically, it's a page that shows simple text -- large header text that may span multiple lines, a separator line, and then smaller descriptive text that may be a variable length. This text does not need to be editable. I'm working using interface builder, but I imagine that what I want done may need to be done programmatically?
Two questions:
-- How do I go about creating these text fields so that they adjust their height based on the content? I'm assuming I would be using a standard "text" field for each, make them not editable, and then programmatically change their height? And then based on the height of the various text fields, I would need to adjust the positioning of the text fields and the divider line between them?
-- How do I go about making the page scrollable? It's possible that the descriptive text will be long and would extend off the edge of the screen. I would want the whole page to be scrollable, not just the descriptive text section. I'm assuming I would place all my elements within a scroll view... but currently when I do that and view it, the view just gets centered (cutting off both the top and the bottom) and I can't scroll it at all.
Thanks for any help!
set the scrollview content size to greater than its actual size to
make it scrollable like this :
scrollView.contentSize = CGSizeMake(YourWidth ,YourHEight ); // Here you can change either of height and width to make it more scrollable in that direction.
You can use UITextView object to have a scrollable text field...
which can scroll to show additional text..just set its editing
property to NO.
Otherwise to dynamically update label height yourself...use
NSString sizeWithFont method
How to increase space between text label and detail text label in table view cell?
I want to do this programmatically.
My updated answer)
I suspect you are using a standard UITableViewCell.
You should create your own subclassed UITableViewCell and put the labels on them directly with as much space as you want between them.
My original answer)
If you're doing this programatically (you're not clear if you're doing this as an Objective-C/Cocoa app), you can adjust row height via:
UITableViewDelegate's tableView:heightForRowAtIndexPath: method
or
UITableView's rowheight property
In Interface Builder (built into XCode 4.2 instead of being a separate app), you can also adjust the row height property in the Size inspector.
As far as I can understand, you want to increase the space between two cells and want to increase the width of separator line which is between the cells.
If you are looking for something readymade in form of some method or delegate, it is not available... you have to write your own trick for this one...!!
Best of luck...!
Sam