How can I justify the text of a UItextView in Objective-C and prevent words from separating?

0

I have a chat in which at the moment of showing the dialogs in a textview, the words are separated when the line breaks, how can I solve this?

The code to create the textView is as follows:

_textView=[[UITextView alloc] init];
[_textView setTextContainerInset:UIEdgeInsetsZero];
_textView.textContainer.lineFragmentPadding = 0;
_textView.dataDetectorTypes=UIDataDetectorTypeAll;
_textView.font=[UIFont systemFontOfSize:17];
_textView.textColor=kTextColor;
_textView.layoutManager.hyphenationFactor = 1;
_textView.backgroundColor=[UIColor clearColor];
_textView.scrollEnabled=NO;
_textView.editable=NO;

-(void)adjustCellWithHeight:(CGFloat)height fromMe:(BOOL)isFromMe andIsMessageSent:(BOOL)isMessageSent message:(NSAttributedString*)text
{
_textView.attributedText = text;

CGFloat fixedWidth = _textView.frame.size.width;
CGSize newSize = [_textView sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)];
CGRect newFrame = _textView.frame;
newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), newSize.height);

//Mae chat view frame according to sender and receiver
//    if (height<80)
//    {
//        height=20;
//    } else if (height<100) {
//        height=50;
//    } else if (height<140) {
//        height=70;
//    }
//if login user is sender
if (isFromMe)
{
    _userNameLabel.textColor=kNavigationTitleColor;
    _textView.textColor=kTextColor;
    _timeLabel.textColor=kTextColor;
    _balloonImageView.image=[Helper balloonImageForSending];
    _userNameLabel.frame=CGRectMake(iPhoneWidth*0.14, 0, iPhoneWidth *0.69, 25);

    _textView.frame = CGRectMake(iPhoneWidth *0.190, 5, iPhoneWidth *0.61, newFrame.size.height);
    CGRect textFrame = _textView.frame;

    _balloonImageView.frame = CGRectMake(textFrame.origin.x-5, textFrame.origin.y, textFrame.size.width+20, textFrame.size.height+18);
    _timeLabel.frame = CGRectMake(_balloonImageView.frame.size.width-5, _balloonImageView.frame.size.height-13, 60, 20);

    //        _textView.backgroundColor = [UIColor redColor];
    _userImageView.frame=CGRectMake(iPhoneWidth * 0.88 , 5, iPhoneWidth*0.10, iPhoneWidth*0.10);

    //        _timeLabel.frame=CGRectMake(iPhoneWidth *0.70 , height+5, 60, 20);
    //        _balloonImageView.frame=CGRectMake(iPhoneWidth*0.12, 0, iPhoneWidth *0.75, height+20);
    //        _textView.frame=CGRectMake(iPhoneWidth*0.145, 5, iPhoneWidth *0.69, height +20);
}
// if message arrives from other user..
else
{
    _userNameLabel.textColor=kNavigationTitleColor;
    _textView.textColor=kTextColor;
    _timeLabel.textColor=kTextColor;
    _balloonImageView.image=[Helper balloonImageForReceiving];
    _userNameLabel.frame=CGRectMake(iPhoneWidth *0.17, 0, iPhoneWidth *0.69, 25);
    _textView.frame = CGRectMake(iPhoneWidth *0.185, 5, iPhoneWidth *0.65, newFrame.size.height);
    CGRect textFrame = _textView.frame;

    _balloonImageView.frame = CGRectMake(textFrame.origin.x-15, textFrame.origin.y, textFrame.size.width+15, textFrame.size.height+15);
    _timeLabel.frame = CGRectMake(_balloonImageView.frame.size.width-6, _balloonImageView.frame.size.height-12, 60, 20);
    _userImageView.frame=CGRectMake(iPhoneWidth * 0.02, 5, iPhoneWidth*0.10, iPhoneWidth*0.10);


    //        _textView.backgroundColor = [UIColor greenColor];
    //        _balloonImageView.backgroundColor  = [UIColor blueColor];
    //        _balloonImageView.frame=CGRectMake(iPhoneWidth*0.13, 0, iPhoneWidth *0.75, height+20);
    //        _textView.frame=CGRectMake(iPhoneWidth *0.185, 5, iPhoneWidth *0.65, height);
    //        _timeLabel.frame=CGRectMake(iPhoneWidth*0.73, height+5, 60, 20);
}

}

    
asked by Esteban Rivas 21.12.2018 в 21:03
source

0 answers