Constraining the area for text in an UILabelView - objective-c

I've got a UILabelView that takes up a large amount of space (and it has to do this).
However, I want the text within it to stay within a small area within it. I've had a look around, and I see there is a method fro containing the area text can occupy in a text view - is there something similar for UILabelView? So I can keep text within a CGRect of the label view?
Thanks for your help,
Sam

Thanks #Dustin - basically it looks like the only way is to put it into a view.

Related

How could I create a horizontal UIPickerView style control?

I want to create a custom UIView that would be equivalent to a horizontal UIPickerView. The data elements, such as "Mountain View, Sunnyvale, Cupertino, Santa Clara, San Jose" would move left to right. The view would be long and thin. 50px in height, 350x in width sort of thing.
I will need to use protocols to obtain my datasource elements likely, but what I'm more interested in figuring out is the visual aspect of this.
How would I animate things left and right? Should I just make one incredibly long view (off screen), and change the frame left and right. This seems like a bad idea, as likely only 3-5 options need to be visible in the control at one time. If the datasource is 100 elements, there is no point in loading the other 95 off screen in a long view.
So perhaps I should load ~9 or something. The 3-5 on screen, plus an additional ~3 left and right. Each time the control is triggered to move left and right, it will load up another element on the view(?).
Is this a good way to achieve this? A long thin view with ~9 UILabel's. As the control moves to the right, I would shift the further left UILabel to move hidden to the far right, and change the UILabel to be the next in the data source.
I also likely want to change the text size based on its position. If it's currently selected, I either want to bold it and possibly increase the font size. How can I gradually achieve this as the view is moved? It would be weird if the text only changed once it was moved perfectly center inside the view. It should likely gradually grow as it gets closer to the middle.
How can I achieve this?
A collection view would do the trick, obviously there's some coding involved.
I'd suggest you to take a look at the code of, or use, the following library.
I've used it once,does almost exactly what you need and works very well:
AKPickerView

How do I make a UITextView Wrap to accommodate text within it?

I have several UITextViews that contain numbers between one and three digits. I'd like these views to expand and shrink as the number becomes larger or smaller. At the moment the text is shrinking and the TextViews size remains the same.
I'd preferable like to do this using the xib file (I'm very surprised this isn't a meagre check box) but a coded answer would be great if this isn't possible.
I'd recommend using the contentSize property of the UITextView:
self.textView.frame = CGRectMake(self.textView.frame.origin.x, self.textView.frame.origin.y, self.textView.contentSize.width, self.textView.contentSize.height);

How to resize UILabels to fit content?

My program currently has thirty UILabels that may contain numbers between one and three digits. I want my UILabels to expand and shrink horizontally as the numbers within them change size. At the moment the text is shrinking and the UILabels size remains the same.
If this can be done just using the xib file this would be preferable to doing so programmatically but if this isn't possible either would be great.
Thanks
After setting the text of the label, call sizeToFit on the label. This will make the label just big enough for the text.
BTW - why do you need to do this? Why not just make the labels big enough for the possible values and leave them that size? What benefit do you think you will get by shrinking the labels?

Sencha Touch - Titlebar to be multi-line text (2 lines)

I'm trying to have a titlebar with two lines of text in the middle rather than the 1 big text.
So it will look something like:
<Back] Registration [Support]
Step 1/5
Basically, instead of the one big text. I want the top line to be small and the bottom line to be bigger. I know frameworks are about making you work faster but it looks like I'm falling at the very first hurdle and I can't see any way of doing something that I could have done in minutes with standard JS/CSS.
I'm guessing I'm going to have to extend this functionality somewhat? I'm using Sencha Architect to try and speed up my work-flow.
Cheers, Dom
Just use the most simple way, like:
title: '<span class="first-line">first line</span><br><span class="second-line">second line</span>'
then increase the height your titlebar or toolbar, let's say about 200px. I guess you cannot see the second line because the bar's height is not enough.

Colored substring in UITextField

I would like to change the color only of particular substrings (keywords) while the user is typing in a UITextField.
In the documentation I saw the property textColor but it does change the color of the entire text string, while I would like to highlight only some keywords.
Is it possible?
The short answer is no.
It's possible if you create your own textfield from scratch using NSAttributedStrings and CATextLayers or Core Text, but this is an incredibly complex and difficult problem.
If you are mirroring what the user types in a preview box of some sort it is possible to create multiple labels or text fields that stay next to each other and have different colors or fonts or whatever. Otherwise, I'm afraid Nick's answer is accurate - within a single textField it ain't happening.
Good luck,
Damien