Changing text layout in a UILabel - Specifically where it starts from - iphone

I have this problem with one of my UILabels, I would like to have the text that it displays begin being drawn at the top left of the label rather than the middle left.
Current screen:
As you can see the word "Description" in the label appears in the centre and to the left of the label. I would like it to start at the top-left instead. How do I implement this either programatically or in IB?
Thanks,
Jack

I'd assume that you're eventually going to put a description in, in which case it would be easier in the long run to simply make the UILabel for "Description" one line high, and put it at the top. Then, just add another multiline UILabel for the actual content. Having separate UILabels will make things simpler later.

Changing the Description label to a UITextView pretty much solved my problem. It allowed for multiple lines of text and was much simpler to implement. Also looked a little prettier.
Thanks for your help, particularly Daniel.
Jack

Related

UITextField, is it possible to get the text to wrap around to another line below the first line?

I've a UITextView, its quiet big, I sized it so it could fit 4 lines of text, so if the user wants to write a long note it can be read while its being written.
The problem is that text stays on the top line and it scrolls horizontally rather than wrapping around and dropping down to a line below it. Like you see when you write a text message on your phone.
Is there anything that can be done to get a UITextField to act like this? Or am I required to use an editable UITextView instead?
Looking at the docs it would seem UITextView cant provide the functionality I need.
Many Thanks
-Code
HI,
I do'nt think , It could be possible by using UITextField (support single line),You will have to use the UITextView (for multiline text) .
See the below tutorial , It grow at runtime while the user type the text using keyboard and can expend till certain line ...
http://www.hanspinckaers.com/multi-line-uitextview-similar-to-sms
If it is an IBOutlet than you can just enable vertical scroll and remove horizontal scroll from scrollers.
Hope this helps.

UIActionsSheet text shadow problem

I have a problem with the text shadow of the UIActionSheet buttons. At iOS 4.0.2 long string were truncated automatically. No at iOS 4.2 these texts are presented with a smaller font. But now the offset of the shadow is corrupted and to big.
Is there a possibility to change/remove the text shadow of the UIActionSheet.
EDIT: I'm building the UIActionSheet not with initWithTitle:, but with the normal init and sets all needed properties afterwards because the number of possible buttons is dynamic and the texts cannot be change. I've tested it with initWithTitle: and got the same results.
You can refer this to truncate your string before displaying it in a UIActionSheet.
I can think there are two workarounds for this (although I would not them myself in my application, reason listed below the workarounds):
In the first case you access the sublayers of UIActionSheet, get the labels, change the shadowOffset and shadowColor before presenting the actionsheet.
Secondly you can initialize the actionsheet with blank titles and add your own labels as subviews on the actionsheet at right places. (More tricky then the first approach).
Now the first approach is very risky as the layer structure of UIActionSheet can be changed by apple in future updates, hence your application may break and would not give good results.
Continuing with second approach is good only when you can calculate the exact frames where you should put your lebels so that they look good. But in your case the number of buttons would also vary, so this approach will take a lot of time initially to get the things working.
Hence, I would go for truncating the strings before I set them as the title of buttons.
Not sure how much would this help. But I am sure that truncating strings before setting them as titles is the best option.
are you doing anything non default for displaying the text?
If you only use UIActionSheet-initWithTitle:… you should write a bug report to Apple.
OR shorten the text to "Frankfurt International (FRA), DE" ;)
This appears to be fixed in 4.30. I found no way of fixing it in 4.2x.

When changing a UIButton's label, how do I prevent it from being shortened using '...'?

I'm working on an iPhone app, and one of the buttons is supposed to have a text label on it that changes. When I set the text label programatically as seen below, it's shortened using '...' instead of displaying the full label -- even though there is plenty of room for it on the button.
self.accuracyButton.titleLabel.text=#"User defined location";
I suspect this may be related by the way it 'resets' to the XIB defined 'accuracy' label whenever I try to click it, but I'm not sure how to fix it or what is going on.
please try
[button setTitle:#"foo" forState:UIControlStateNormal];
Yesterday I had the same issue, the button showed the three dots, even if there was enough room.
Using setTitle:forState: instead of setting the property displayed the text correctly
You can change the amount of padding around the label by using this:
#property(nonatomic) UIEdgeInsets titleEdgeInsets
Not sure why it cuts off, but might I suggest simply using a UILabel over the top of the button? That allows much more refined control of the label boundary and size.

Getting around the limitations of iPhone's UITextField

I have spent a few days trying to get around the limitations with UITextField, namely no text wrap and number of lines. I have created a UILabel, which is used to display the text entered in UITextField and does all the formatting stuff properly. The UITextField is hidden and the user sees all the text entered only in UILabel as it's being entered.
Everything is working perfectly except for the lack of a cursor on the UILabel to show the user where the next character typed into the field will show up.
I have experimented with using various characters as cursors on the label. But there is no getting around the fact that it is not the standard blinking cursor indicator on the iPhone and so the whole thing just looks wrong.
Before I abandon ship and go for a UITextView (with its own set of issues) I was wondering if anyone has any ideas as to how a blinking cursor can be added to the text field on a label text.
Thanks in advance.
Your approach has other issues which make it worth rethinking the strategy.
How does selection look like?
copy + paste?
Do you handle right to left languages?
Auto correction?
The list is certainly longer, but I think it's enough to consider other solutions. But I agree that all of UIKit's text handling is a bit poor.
If you don't need to support selection, copy and paste, and only need multiline input, you could use a | character and animate it as if it were blinking... either that or perhaps a custom overlay view on top of the label, that would implement the cursor drawing, animation and positioning based on the length of the string and the font used.
– sizeWithFont:forWidth:lineBreakMode:
– sizeWithFont:constrainedToSize:
– sizeWithFont:constrainedToSize:lineBreakMode:
– sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:
may help to achieve just that.
So what are the issues preventing you from going to a UITextView? It seems possibly easier to address those.

Custom UITextField/UIButton

What I'm trying to do is replicate the NSTokenField like UITextField seen in the Mail app and Messages app (type a contact and it comes up with suggestions).
I've got the autocompleting working perfectly, when you type in a UITextField, a UITableView pops up showing any matches that it can find in an array, when you click one it adds it to the UITextField. I'm really happy with this so far.
The problem I've run into now is making the controls look like those in the native apps. Afterall, design is everything!
My first question is how can I add that shadow look to the UITableView? Looks like it's sunk down behind the UITextField.
Secondly, I know I'm going to have to subclass the UITextField to make it look the way I'd like it to, but I've got no idea where to start with that. Some pointers or a sample would be great!
Lastly, I think I need to create a custom UIButton with space for text and the blue gradient then add it to the UITextField. Same problem as with the UITextField, not really sure how to subclass the UIButton (what methods it needs to draw and stuff) or how to add it to the UITextField in such a way that when you click backspace on in the UITextField, the button will be highlighted, then deleted if backspace is clicked again (exactly how the NSTokenField works).
I've included an image just so you can see what I'm talking about:
http://www.thermoglobalnuclearwar.com/stuff/mail.jpg
I have taken a look at Joe Hewitts Three20 project but I couldn't make heads or tails of it.
I'd like to start very simply and understand everything that's going on rather than just dragging his code into mine and not having any idea what's going on!
Any help is greatly appreciated!
Thanks,
Tom.
Have you considered using the Three20 library? It contains a control which I think does what you want (TTPickerTextView).
As the website description states
TTPickerTextField is a type-ahead UITextField. As you type it searches a data source, and it
adds bubbles into the flow of text when you choose a type-ahead option. I use this in
TTMessageController for selecting the names of message recipients.
At a minimum the source code might give you some pointers on how to achieve the various visual effects.
Okay, I've got the shadow working underneath the UITextField, and I've added the "To:" label to it. It looks great!
So the final thing is the blue NSToken like control. I've started to think the easiest thing is just to subclass a UIView and draw the blue gradient and label inside it. Which brings me to some more questions:
I found this: http://github.com/leonho/iphone-libs/tree/master which draws a nice rounded view and I've adapted it to add some text to it rather than a number, what I don't know how to do is draw a gradient instead of a solid block of colour.
After that there's just the matter of adding the rounded views to the UITextField, moving the cursor and working out how to delete the views when the cursor reaches them, but I'll tackle that when I need to.