Before I start, details_Label
is UITextView
. I have wrong naming because earlier it was label but I changed to UITextView for copy text and other functionalities.
Below is what I have
details_Label.text = [NSString stringWithFormat:@"%@", [[[detailsArray objectAtIndex:0] valueForKey:@"Details"] substringToIndex:200]];
NSMutableAttributedString *attributedString;
attributedString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@", details_Label.text] attributes:@{ NSFontAttributeName : [self adjustDefaultFont:85], NSLigatureAttributeName: @2}];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init] ;
[paragraphStyle setAlignment:NSTextAlignmentCenter];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [details_Label.text length])];
details_Label.editable = NO;
details_Label.selectable = YES;
details_Label.tintColor = pBlackColor;
[details_Label sizeToFit];
[details_Label layoutIfNeeded];
[details_Label setTextContainerInset:UIEdgeInsetsMake(0, 0, 0, 0)];
[details_Label.textContainer setSize:details_Label.frame.size];
details_Label.frame = CGRectMake(50*iPhoneFactorX, startX, 980*iPhoneFactorX, details_Label.frame.size.height);
This is how I am displaying the text.
The problem is half word is going in next line is as shown in below image...
At the start I thought it was because of long text, however when I just take first 200 characters, still problem is coming.
details_Label.text = [NSString stringWithFormat:@"%@", [[[detailsArray objectAtIndex:0] valueForKey:@"Details"] substringToIndex:200]];
Any idea what is going wrong?
Edit 1
When I print the NSAttributedString, below is what I get.
NSFont = " font-family: \"Arial-BoldMT\"; font-weight: bold; font-style: normal; font-size: 34.72pt"; NSParagraphStyle = "Alignment 1, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (\n), Lists (\n), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0"; }
details_Label.numberOfLines = 0; details_Label.lineBreakMode = UILineBreakModeWordWrap;
– Mrunaldetails_Label
isUITextView
and I tried with that too before – Fahim ParkartextContainer
property, like this :details_Label.textContainer.lineBreakMode = UILineBreakModeWordWrap;
– Mrunal