Search code examples
iosswiftword-wrap

I have problem with "Re-Send?" text wrapping on textview


"I have label that text is "Don't receive Verification code ? Re-Send?", Here I am using word wrapping . But while un wrapping it is coming "Send?" in next line ,I need alway "Re-Send?" together either it is after "?" (Don't receive Verification code ? Re-Send?) or in next line as "Re-send?"., Can anybody suggest me how to solve this ?"

If i use "Re_Send" then it is coming next line but if i use "Re-Send" the word is splitting.

let attributeText = NSMutableAttributedString(string: "Don't you get 
verificationcode in your email Inbox? ", attributes: 
[NSAttributedString.Key.foregroundColor: UIColor.red, 
NSAttributedString.Key.font: UIFont.systemFont(ofSize: 
22),NSAttributedString.Key.paragraphStyle: style])


attributeText.append(NSAttributedString(string: " Re-Send ", 
attributes: [NSAttributedString.Key.foregroundColor: UIColor.green, 
NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 22)]))

let linkRange = attributeText.mutableString.range(of: " Re-Send ")
    attributeText.addAttribute(NSAttributedString.Key.link, value: 
linkKey, range: linkRange)


txtview.attributedText = attributeText
txtview.textContainer.lineBreakMode = NSLineBreakMode.byWordWrapping
txtview.textAlignment = .center 

I need it should be either "Don't you get verificationcode in your email Inbox? Re-Send?" OR "Don't you get verificationcode in your email Inbox? Re-Send? " . (Depends on my screen length).


Solution

  • Use (U+2011 NON-BREAKING HYPHEN) instead of - (U+002D HYPHEN-MINUS).

    attributeText.append(NSAttributedString(string: " Re‑Send ", 
    

    or

    attributeText.append(NSAttributedString(string: " Re\u{2011}Send ",