I am using UILabel to display text. Sometimes, it creates orphan and widow problem in the copy of text, the alignment of the text is set to 'justified', also the hyphenation factor is set to 1.0.
How can I solve the widow & orphan problem?
I want justified text with hyphens for word-wrap and want to remove orphan and widow.
I had set attributed text to label and the size of label is set depending on the device width.
Here is the code for attributed text:
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = NSTextAlignment.Justified
paragraphStyle.hyphenationFactor = 1.0;
let strTwo = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum";
let attrlblTwo = NSAttributedString(string: strTwo,
attributes: [
NSParagraphStyleAttributeName: paragraphStyle,
NSBaselineOffsetAttributeName: NSNumber(float: 0),NSKernAttributeName: 0, NSFontAttributeName : lblTwo.font
])
self.lblTwo.attributedText = attrlblTwo