I have created a text field using the story board in Xcode 5 - I have applied a background and applied text to the field - but the brief requires the background to expand according to the length of the containing text (the text is a persons name - as shown below )
Is it possible to auto expand the width based on the content size?
try to use -sizeToFit method .
Related
I am beginner in iOS app development, I am working on a project that was done by someone else. So my problem is the label is not fully showing its contents:
check the second column under 'customer name'.
I did some basic alterations to the label but it makes no change at all. This is a collection view, there is another view inside the collection view cell which holds the title label and description label.
I searched everywhere but didn't get any proper answer please help.
Label in iOS does not change its size to suit the contents, you need to adjust it in your code. Your options are either decrease the font size to suit the description label size, or adjust the description label's height/width to make room for current content. I'd do a combination of both (slightly reducing the font size of the label's text, and at the same time making all the cells a bit wider and taller).
Oh, there is also a way to automatically shrink the font size if the contents doesn't fit the space. So, you'd need to check the option for your description label. Here's how you might do it: how to make UILabel autosize text in storyboard (or interface builder), NOT programmatically
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 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
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.