-(void) awakefromnib {
[Self.descriptionlabel addobserver:self forkeypath:@ "text" Options:nskeyvalueobservingoptionnew Context:nil];
[Super awakefromnib];
Initialization code
}
-(void) Observevalueforkeypath: (NSString *) KeyPath Ofobject: (ID) object change: (nsdictionary<nsstring *,id> *) Change context: (void *) context
{
Self.descriptionLabel.attributedText = [[self class] attributeWithString:self.descriptionLabel.text] copy];
}
+ (nsmutableattributedstring *) attributewithstring: (NSString *) string
{
nsmutableattributedstring *muattrstring = [[Nsmutableattributedstring alloc] initwithstring:string];
Nsmutableparagraphstyle *paragtaphstyle = [[Nsmutableparagraphstyle alloc] init];
Paragtaphstyle.alignment = nstextalignmentjustified;
paragtaphstyle.paragraphspacing = 11.0;
Paragtaphstyle.paragraphspacingbefore = 10.0;
paragtaphstyle.headindent = 0.0;
Paragtaphstyle.linebreakmode = nslinebreakbywordwrapping;
Paragtaphstyle.tailindent = 30.0;
Paragtaphstyle.firstlineheadindent = self.descriptionLabel.font.pointSize * 2.0;
Nsdictionary *dic = @{
Nsforegroundcolorattributename:colors (@ "#585C67"),
Nsfontattributename:fontwithsize (14.0),
Nsparagraphstyleattributename:paragtaphstyle,
nsunderlinestyleattributename:@ (Nsunderlinestylenone)
};
[muattrstring Setattributes:dic range:nsmakerange (0, muattrstring.length)];
return muattrstring;
}
+ (CGFloat) descriptionlabelwidth
{
return screen_width-30*2;
}
+ (CGFloat) Descriptionheightwithtext: (NSString *) Text width: (cgfloat) width
{
Nsmutableparagraphstyle *paragtaphstyle = [[Nsmutableparagraphstyle alloc] init];
Paragtaphstyle.alignment = nstextalignmentjustified;
paragtaphstyle.paragraphspacing = 11.0;
Paragtaphstyle.paragraphspacingbefore = 10.0; Spacing between paragraphs
paragtaphstyle.headindent = 0.0;
Paragtaphstyle.linebreakmode = nslinebreakbywordwrapping;
Cgsize size = [Text Boundingrectwithsize:cgsizemake (width, Cgfloat_max)
Options:nsstringdrawingusesfontleading| Nsstringdrawinguseslinefragmentorigin
Attributes:@{nsfontattributename:fontwithsize (14.0),
Nsparagraphstyleattributename:paragtaphstyle}
Context:nil].size;
Return size.height + 10.0 + 75.0 + paragtaphstyle.paragraphspacingbefore;
}
IOS attributestring Line wrapping