UIlabel truncating text after linebreaks in iOS7 only - ios7

I am trying to display a UIlabel with a text having a linebreak. It works fine on iOS6 but on iOS7 , it truncates the text after linebreak is encountered.
I have kept
label.numberOfLines = 1;
The UIlabel frame which I am setting is also correct. I have cross checked it.
Does anyone has any other pointers to this problem?

label.numberOfLines = 0;
label.lineBreakMode = UILineBreakModeWordWrap;
This will allow the label to dynamically assign as many lines into the label as will fit into the label.frame.size.height of the label based on the current font.

Related

How to enlarge UILabel width (letter spacing) in Objective-C?

This is the code I am using for the UILabel title of my View Controller:
UIFont *bebasFont = [UIFont fontWithName:#"Bebas" size:100];
RestaurantsTitle.font = bebasFont;
RestaurantsTitle.text = #"RESTAURANTS";
and I need to enlarge the space between the letters of the title but I don't know how to do it.
Setting a width to the text field and not the frame would also work if that is also possible?
I need to enlarge the space between the letters
Use NSAttributedString and increase the kerning of the string.
https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSAttributedString_Class/index.html
https://developer.apple.com/library/ios/documentation/UIKit/Reference/NSAttributedString_UIKit_Additions/index.html#//apple_ref/doc/c_ref/NSKernAttributeName

Dynamically changing font size of text without changing UILabel size

I am developing an application in which I am having fixed size UILabel which may contain text of any size.
I need to resize font size without changing UILabel size.
Following is how I have tried to achieve this:
UILabel *errorMessageLabel=[[UILabel alloc]initWithFrame:CGRectMake(0,50,300,30)];
errorMessageLabel.lineBreakMode =NSLineBreakByTruncatingTail;
errorMessageLabel.numberOfLines = 0;
errorMessageLabel.adjustsFontSizeToFitWidth=YES;
errorMessageLabel.adjustsLetterSpacingToFitWidth=YES;
if ([[[UIDevice currentDevice] systemVersion] floatValue]>=7.0) {
[errorMessageLabel setTextAlignment:NSTextAlignmentCenter];
}
else{
[errorMessageLabel setTextAlignment:UITextAlignmentCenter];
errorMessageLabel.minimumFontSize=5.0;
}
[errorMessageLabel setTag:405];
[errorMessageLabel setFont:[UIFont systemFontOfSize:13]];
[backgroundView addSubview:errorMessageLabel];
Above solution works for iOS 7 but when I try to run this on iOS 6 it changes font size properly but sets text alignment to left ignoring its centre alignment.
Can any one please let me know how I can achieve this? I tried to search form other solution but nothing is working. I cannot change UILabel's size
errorMessageLabel.numberOfLines = 1;
errorMessageLabel.adjustsFontSizeToFitWidth = YES;
errorMessageLabel.minimumFontSize = MIN_FONT_SIZE;

UITextView text is missing when adjust frame according to text in iOS7?

Hi I am trying to set UITextView height as per content. Its working fine for adjusting frame of UITextView.
But coming to text is missing as like below image shown. This happn only in iOS7 . Its displaying well in iOS6. If i tap on textview i started to edit the textview complete text is dispalying.
I wrote the fllowing lines of code` notesField.text = [editWellObject objectForKey:#"Notes"];
// Adjusting Frame as per text
CGSize size = [notesField sizeThatFits:CGSizeMake(notesField.frame.size.width, FLT_MAX)];
CGRect frame = notesField.frame;
float difference = size.height - frame.size.height;
frame.size.height = size.height;
notesField.frame = frame;
Please help me in this issue. Thanks in Advance.
Few days back I was struggling with the same issue and I have found solution with resetting property scrollEnable from NO to YES. Following is my code snippet
internalTextView.scrollEnabled = NO;
if (newSizeH >= maxHeight)
internalTextView.scrollEnabled = YES;

Change text parameters in UITextView

I am trying to display some text in a UITextView (no editable) and I am having some problems to change font size, color...
I am using xcode 5 with ios6 appearance. I tried to change parameters in nib file: arribute inspector> text view.
But all I try, seems to do nothing. Nothing changes, I see the text equal as if I didn't modify anything.
I don't write text inside uitextview, I just show it from a variable.
I had the same problems and had already an answer here
You need to set the text of your UITextView and after you can set the font and the color :
_myTextView.text = #"text";
[_myTextView setFont:[UIFont fontWithName:#"Helvetica Neue" size:18.0f]];
_myTextView.textColor = [UIColor whiteColor];
I had a similar problem before. It got fixed when I did the customization after selecting the entire default text.
Here is a sample screenshot :
Hope this helps !

How to fit a text with various length in a UITableViewCell?

What I have is:
a NSString which can have any length between 1 and 400 characters
a UITableViewCell (custom layout)
I tried using an UILabel with multiple lines, set the text, and call sizeToFit. That doesn't work always, most of the time the UILabel just clips off the part of the string that doesn't fit. Also, due the varying length of the text I'd need differently sized UITableViewCells, and at the time "tableView: cellForRowAtIndexPath:" is called I don't know what the height will be.
So what I need is a non-scrolling UI element which is able to display text and resizes its height (the width should remain constant) to exactly fit the text. As mentioned the sizeToFit method produces mostly garbage.
You can use SizeWithFont: to calculate the desired height for your cell and store it in an Array so that you can return that height in HeightForRowAtIndexPath. If you need to update the text, just have a method that re-calculates the height, saves it to the array, and updates the table. Something like:
CGSize constraintSize;
constraintSize.width = 290.0f;
constraintSize.height = MAXFLOAT;
NSString *text = #"YOUR TEXT"
CGSize theSize = [text sizeWithFont:[UIFont systemFontOfSize:15.0f] constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
NSLog(#"height: %f",theSize.height);
will give you the height.
This configuration should give you something simillar to what you see when you enter a loooong number in the phone app -
label.minimumFontSize = 4; //a very small font size
label.adjustsFontSizeToFitWidth = YES;
label.lineBreakMode = UILineBreakModeWordWrap;// change to what works for you
label.numberOfLines = 0;
See lineBreakMode Documentation