If I set linebreakmode to truncation tail in the TTTAttributedLabel Example App "Espresso" everything looks like it should be in iOS 5 Simulator but if I run the App in iOS 6 Simulator the text gets truncated after the first line although the text goes over 3 lines. Number of lines are set to zero. Did I miss something? After I noticed this behavior in the Espresso App I can stop worrying about the brokeness of the code in my own app.
Any suggestions? Thanks!
I currently faced the same problem. Try setting the LineBreakMode before you actually set your text. E.g.:
TTTAttributedLabel* descriptionLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectMake(20, 120, 280, expectedSize.height)];
descriptionLabel.lineBreakMode = UILineBreakModeWordWrap;
descriptionLabel.numberOfLines = 0;
descriptionLabel.text = description;
Labels and textviews in iOS 6 support attributed text natively. So if you don't need to support older versions of iOS, you can get rid of 3rd party control.
In my case, for some reason following code was causing the label to show only one row. Removing it helped
' self.attributedLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;'
Strangely the problem solved itself. I could not figure out why this particular problem happened on iOS6 Simulator but now it works with NSLineBreakTailTruncation on iOS6 Device and Simulator.
Thank you for your responses!
You can have a try.
NSMutableAttributedString * mutableAttributedString = [[NSMutableAttributedString alloc]initWithString:text];
[self.attributedLabel setText:mutableAttributedString afterInheritingLabelAttributesAndConfiguringWithBlock:nil];
Related
I've been using React Native SVG for a project and with the upgrade to iOS 14 I've started to receive a crash on a resizable box. I've tracked the crash down to three assignments in a library but am unsure of why they cause a EXEC_BAD_INSTRUCTION or a EXC_BAD_ACCESS.
This crash occurs only after the initial render within the app when you resize the box. The first render is fine and then the subsequent move of the item causes the fault. This code worked in iOS 13 but does not in iOS 14.
I've created a reproducible example here. I've also created an issue on the repo here.
In the library I've attempted to hard code the assignments to known good values assuming something went wrong with how they were being assigned with no luck.
The following is where I receive the error:
label.attributedText = (__bridge NSAttributedString * _Nullable)(attrString);
label.baselineAdjustment = UIBaselineAdjustmentNone;
//label.lineBreakMode = NSLineBreakByWordWrapping;
label.backgroundColor = UIColor.clearColor;
//label.textAlignment = NSTextAlignmentRight;
label.numberOfLines = 0;
label.opaque = NO;
label.font = font;
//label.textColor = [UIColor colorWithCGColor:color];
This is from line 203 in RNSVGTSpan, the comments are the lines I've removed to make it work but this takes away functionality that is used.
I'm at a loss as to why this would work on the initial render but not with the subsequent changes in iOS 14 but works flawlessly in iOS 13.
I haven't done any iOS development for like a year.
I updated OS to OS X 10.11.5 on my MacBook Pro.
I updated Xcode to v7.3
I did Xcode > New project, single view.
I set target OS to v7.1 because I'm testing on an iPhone4.
I used Storyboard to drag a Label onto the screen and set to Hello World.
But when I run simulator iPhone4S, it displays label then it disappears.
When I run on actual iPhone4, it displays nothing (all white).
Make sure that you didn't mistakenly drag the label onto your LaunchScreen.storyboard instead of your required storyboard. That would explain the vanishing part. Other than that you should probably use Auto-Layout for new projects. A convenient way to do a quick base layout is to select the UILabel and then go to the Editor menu and at the very bottom where it says "Resolve Auto-Layout Issues" select the entry Reset to Suggested Constraints..." in the lower section. Finally you may want to test on a different simulator - maybe for the iPad 2 just to check that your elements are there.
Try to add programmatically -
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(40, 30, 300, 50)];
label.backgroundColor = [UIColor blackColor];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.numberOfLines = 0;
label.text = #"Hello World";
[self.view addSubview:label];
if it is showing ,, then you have mistake in to adding the storyboard.
May be it helps you or feel free.
I had the exact same problem and what I did to fix this issue was clicking on the view and on the right pane, on the ¨Interface builder document¨, I changed the Opens in and that solved the problem.
I have updated my device iOS to iOS 8 and now multiline label is not working. Its displaying very weird screen shot attached.
So please can you suggest me the solution.
I already set Number of lines =0 and it was working perfect in ios 7.
Not using Autolayout and story board.
This code help you.It works fine me.Edit your code according to need
UILabel *problem = [[UILabel alloc] initWithFrame:CGRectMake(40, 100, 200, 100)];
problem.lineBreakMode=NSLineBreakByWordWrapping;
problem.text=#"Please use this code it may help you it works fine for me";
problem.numberOfLines=0;
[self.view addSubview:problem];
Strangely enough, this fix doesn't work if you don't use all of it:
Set the line break mode to word wrapping (if that's the affect you want).
Set the number of lines to 0 (I had it set to 2 and it still didn't work).
Not sure if something changed here with the introduction with iOS 8 but my previous code (just setting the number of lines to 2) was working great on iOS 7.
Anyone else face a similar issue?
Do you use a custom font?Try changing the font.
I am developing an application that target iOS6+.
I have a text view with with large attributed text. Maybe 1000 lines odd lines red color and other lines green color.
I use below code for changing the font size of the textview:
self.doaTextView.editable= YES;
self.doaTextView.font = [UIFont systemFontOfSize:self.FontSilder.value];
self.doaTextView.editable= NO;
but it takes much time. It is about 2 second on iOS 7 and about 5-10 second on iOS 6!!!
(I enable and disable editable feature, becasue if I do not do this the changes not appear in iOS 6. Please see here)
What is the problem?
Edit
I found this topic related to this problem too. Really there is not any solution for this?
I finally fixed this problem by recreating my attributedtext again and setting it as a new attributedtext to my uitextview.
I have a problem regarding incompatibility of ios5 vs ios6
While I was working on my project with ios5
label.textAlignment = UITextAlignmentCenter;
then updated to ios6
label.textAlignment = NSLineBreakByTruncatingTail;
Once I run my code on the device which ios5 installed, that give me error.
I am about to upload my app to appstore, however I want my app also supports ios5 as well. How I am going to handle both ios5 and ios6!
Thanks in advance!
The acceptable values for NSTextAlignment are:
NSTextAlignmentLeft
NSTextAlignmentCenter
NSTextAlignmentRight
NSTextAlignmentJustified
NSTextAlignmentNatural
Of those any of the first three will work equally under iOS 5 and 6.
NSLineBreakByTruncatingTail isn't really a valid type of text alignment though it'll look like NSTextAlignmentNatural at runtime because of the way the C enums line up.
So you'll need either to switch to NSTextAlignmentLeft across the board or to do a functionality check. Thankfully the change in text alignment type is in support of the new ability to push attributed strings to UILabel (and elsewhere) so that gives you something to hang off.
E.g.
if([label respondsToSelector:#selector(attributedText)])
label.textAlignment = NSTextAlignmentNatural;
else
label.textAlignment = NSTextAlignmentLeft;
Though the else is technically redundant because NSTextAlignmentLeft is the default value.