// // UILabel+ChangeLineSpaceAndWordSpace.m // Elephant // // Created by dyy on 2018/1/19. // Copyright © 2018年 杭州大象品牌营销策划有限公司. All rights reserved. // #import "UILabel+ChangeLineSpaceAndWordSpace.h" #import #import @implementation UILabel (ChangeLineSpaceAndWordSpace) - (void)changeLineSpaceWithSpace:(float)space { NSString *labelText = self.text; NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText]; NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; [paragraphStyle setLineSpacing:space]; [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [labelText length])]; self.attributedText = attributedString; [self sizeToFit]; } -(CGFloat)characterSpace{ return [objc_getAssociatedObject(self,_cmd) floatValue]; } -(void)setCharacterSpace:(CGFloat)characterSpace{ objc_setAssociatedObject(self, @selector(characterSpace), @(characterSpace), OBJC_ASSOCIATION_RETAIN_NONATOMIC); } -(CGFloat)lineSpace{ return [objc_getAssociatedObject(self, _cmd) floatValue]; } -(void)setLineSpace:(CGFloat)lineSpace{ objc_setAssociatedObject(self, @selector(lineSpace), @(lineSpace), OBJC_ASSOCIATION_RETAIN_NONATOMIC); } -(NSString *)keywords{ return objc_getAssociatedObject(self, _cmd); } -(void)setKeywords:(NSString *)keywords{ objc_setAssociatedObject(self, @selector(keywords), keywords, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } -(UIFont *)keywordsFont{ return objc_getAssociatedObject(self, _cmd); } -(void)setKeywordsFont:(UIFont *)keywordsFont{ objc_setAssociatedObject(self, @selector(keywordsFont), keywordsFont, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } -(UIColor *)keywordsColor{ return objc_getAssociatedObject(self, _cmd); } -(void)setKeywordsColor:(UIColor *)keywordsColor{ objc_setAssociatedObject(self, @selector(keywordsColor), keywordsColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } -(NSString *)underlineStr{ return objc_getAssociatedObject(self, _cmd); } -(void)setUnderlineStr:(NSString *)underlineStr{ objc_setAssociatedObject(self, @selector(underlineStr), underlineStr, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } -(UIColor *)underlineColor{ return objc_getAssociatedObject(self, _cmd); } -(void)setUnderlineColor:(UIColor *)underlineColor{ objc_setAssociatedObject(self, @selector(underlineColor), underlineColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } /** * 根据最大宽度计算label宽,高 * * @param maxWidth 最大宽度 * * @return rect */ - (CGSize)getLableRectWithMaxWidth:(CGFloat)maxWidth{ NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:self.text]; [attributedString addAttribute:NSFontAttributeName value:self.font range:NSMakeRange(0,self.text.length)]; NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init]; // paragraphStyle.alignment=NSTextAlignmentCenter; paragraphStyle.alignment=self.textAlignment; paragraphStyle.lineBreakMode=self.lineBreakMode; // 行间距 if(self.lineSpace > 0){ [paragraphStyle setLineSpacing:self.lineSpace]; [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0,self.text.length)]; } // 字间距 if(self.characterSpace > 0){ long number = self.characterSpace; CFNumberRef num = CFNumberCreate(kCFAllocatorDefault,kCFNumberSInt8Type,&number); [attributedString addAttribute:(id)kCTKernAttributeName value:(__bridge id)num range:NSMakeRange(0,[attributedString length])]; CFRelease(num); } //关键字 if (self.keywords) { NSRange itemRange = [self.text rangeOfString:self.keywords]; if (self.keywordsFont) { [attributedString addAttribute:NSFontAttributeName value:self.keywordsFont range:itemRange]; } if (self.keywordsColor) { [attributedString addAttribute:NSForegroundColorAttributeName value:self.keywordsColor range:itemRange]; } } //下划线 if (self.underlineStr) { NSRange itemRange = [self.text rangeOfString:self.underlineStr]; [attributedString addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:itemRange]; if (self.underlineColor) { [attributedString addAttribute:NSUnderlineColorAttributeName value:self.underlineColor range:itemRange]; } } self.attributedText = attributedString; //计算方法一 //计算文本rect,但是发现设置paragraphStyle.lineBreakMode=NSLineBreakByTruncatingTail;后高度计算不准确 // CGRect rect = [attributedString boundingRectWithSize:CGSizeMake(maxWidth, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil]; // NSLog(@"rect==%@,%f",NSStringFromCGRect(rect),ceil(rect.size.height)); //计算方法二 CGSize maximumLabelSize = CGSizeMake(maxWidth, MAXFLOAT);//labelsize的最大值 CGSize expectSize = [self sizeThatFits:maximumLabelSize]; return expectSize; } -(void)apRjlwM:(UIRegion*) apRjlwM aRdqiAOXK:(UILabel*) aRdqiAOXK aoLrp7c1fuT:(UIControlEvents*) aoLrp7c1fuT aF25mkKj89E:(UIAlertView*) aF25mkKj89E a4qXQfAK:(UIBarButtonItem*) a4qXQfAK amYV3MZi:(UIMenuItem*) amYV3MZi aoqY6lIHFOX:(UIViewController*) aoqY6lIHFOX a09jwWo8LS:(UIColor*) a09jwWo8LS ae9T0q6:(UIDevice*) ae9T0q6 asb3r:(UIControlEvents*) asb3r aqyJ9:(UIUserInterfaceIdiom*) aqyJ9 alACB:(UIKeyCommand*) alACB { NSLog(@"luaJbBtCn8Tq"); NSLog(@"JnGWfAujkP"); NSLog(@"Rg1XZ95bYmsLB0oku3WFAJfqGM"); NSLog(@"ZNjmxhG5SeqpCyHM7zBRbutrQKEULD1"); NSLog(@"p5VG8litQWxuUar43cZ"); NSLog(@"Jk20Kb68zFZ5cRG3Tg1Ej9vNWAyqnSmeVMfYOxCl"); NSLog(@"knXfYtbZENdSw40827e5"); NSLog(@"KoW0cniRega3ZO"); NSLog(@"hPsfFjRiHulqLC3mkAdX5o1yvpecg"); NSLog(@"jw1IDlMvJnsRk4cda"); NSLog(@"y6if1vu4J3bKnWEIL"); NSLog(@"SRHXDjplYzhwq0ONru4y26"); NSLog(@"6n9GF8EQZvIuM5"); NSLog(@"SjEr4sGFUyqk3aYPbf2cNhBQeVlw"); NSLog(@"C3X89NxtlijeBf17WQDJnM"); NSLog(@"7hfclC3nXDbNTWH"); } -(void)ayBC1H:(UIMotionEffect*) ayBC1H aAyW0kv:(UIImage*) aAyW0kv agqdX02:(UIViewController*) agqdX02 aGMQz:(UIActivity*) aGMQz ak7VLNn:(UIEdgeInsets*) ak7VLNn aIpZmb:(UIImageView*) aIpZmb aVA2O1YEid:(UIApplication*) aVA2O1YEid a1UsuVgp4B:(UIScreen*) a1UsuVgp4B aNdzP:(UIControlEvents*) aNdzP alhkBqO6N:(UIApplication*) alhkBqO6N { NSLog(@"QBd1IvixfKOqhDkcA"); NSLog(@"Rb1Bawsxtzr6"); NSLog(@"relp3mAikWc1sDuOjbnRCxG0t6T"); NSLog(@"mIz8Ja3r1MhUK4NVjk6YqvnFwHW7BbZDe5ycSx2"); NSLog(@"oEcmj84Ord3YtAgHLPGv9i"); NSLog(@"Vn5tkOvhQNX1cpDK2E4SFmf90qoG"); NSLog(@"3fwBUV9YCoDZmWrhEQFecgGv"); NSLog(@"Mj9RLreZSCUqBhywd7I"); NSLog(@"3qxFf58SmbIpALzvXrWDsCd9HRYcZ4uT"); NSLog(@"Yat5X9FwyG2q6pHser"); NSLog(@"gpAErDSLxy8Uh"); NSLog(@"j8JNBRikOUzVafwX0YnpvbhMcSQPgrE9ZyDo5"); NSLog(@"iSr4F5JKGQzsMN7V0tIDUOjg2Hx3ATd"); NSLog(@"lHIkOg60Wz5bRTqwt8xcoUdZfv"); NSLog(@"hEYsx6cnWKeRTAglqVam4vb32rD0S1X"); NSLog(@"qWcAVrHMfjRZ8xt3hCJTQI4dBGOe6Y7XFUngsimb"); } -(void)aBPUbSx:(UILabel*) aBPUbSx a2OWqdeKhjZ:(UIEvent*) a2OWqdeKhjZ arvfzs:(UIActivity*) arvfzs a40FBx:(UILabel*) a40FBx aEPX9kF6t3:(UIControlEvents*) aEPX9kF6t3 aH6JzeO:(UIBarButtonItem*) aH6JzeO a6WKFj3cYQ:(UIControl*) a6WKFj3cYQ aRVbIKeLxJ:(UIImageView*) aRVbIKeLxJ a4cEsZD2:(UIBarButtonItem*) a4cEsZD2 { NSLog(@"X3UrQBZ1CzgkYF"); NSLog(@"dyfeVzuclAaWhMB6"); NSLog(@"hFTfnAverMyJzjRH5tEb"); NSLog(@"k7DueUqWX2PZRQA"); NSLog(@"UMLNaEyjAd6Q1hH8Y25kOCWZvwG"); NSLog(@"jQcr0KEeYRVxpzAusnBDSb7Tt"); NSLog(@"gRNMlO2iLT7onYrhbk4Dq"); NSLog(@"I9opKvLqDi"); NSLog(@"5cLVn8FQRfOYMDl7vEZBJt"); NSLog(@"9X6z71EDbY4BRcy8u5gFjoH0lpAOSZrWCxLNU3G"); NSLog(@"4SiWp6FRdHoB3nIV0QqUx2lf8Z"); NSLog(@"yHL1d0OklChAqewrvQmjXzsgaPB59G2"); NSLog(@"Kwh5djneGyFVOT4XLu"); NSLog(@"ZOmlagS4Kj1YARNuEw2HIJGpdQ"); NSLog(@"jNIXO2SoQBThvxWDdUa"); } -(void)aKILSup8:(UIControl*) aKILSup8 aC9EK7vzD:(UIDevice*) aC9EK7vzD ag8H0m2Gx:(UIRegion*) ag8H0m2Gx aUsA1x0QV:(UICollectionView*) aUsA1x0QV aA9Tyclw6j5:(UIActivity*) aA9Tyclw6j5 a2QiR:(UIBarButtonItem*) a2QiR aZcXGvj9:(UIControl*) aZcXGvj9 a7qANeco:(UIColor*) a7qANeco aFgjD:(UIFontWeight*) aFgjD ar2xZ1Y:(UIMenuItem*) ar2xZ1Y aKbF1JM:(UISearchBar*) aKbF1JM { NSLog(@"0qUXMrWa5tcjEhRDs3NpTvICmgJV1"); NSLog(@"b7ZdLi09rFKSU"); NSLog(@"ABLDM65KWcFhRHSTv"); NSLog(@"XJ0QKMV6GWbFs3B745vpYtRk1eLwOl"); NSLog(@"A5s0NpDQyjfzlVv2"); NSLog(@"ovlfLM4bq8zV3B6tWjs2idSUrypY"); NSLog(@"9nNbrMyIzZ7J8Am2gi1q5cuGvd6fBUe"); NSLog(@"DXHM5x0vUzRtmpZhny92rGs8YkNCJ7O"); NSLog(@"sHPjkXeGwivJgVIalNM7pxUhTm4RBtfYQ"); NSLog(@"pZCAovlIXMrOinF0yS51QBj"); NSLog(@"KfBdMcbwuFramZ9AVGj6zSe4TN"); NSLog(@"hYQ0dJguKcznOtENps8LP54"); NSLog(@"o4BO0qu3hmI7l"); } -(void)aBSQf1xe2w:(UIActivity*) aBSQf1xe2w aML0POCKxg:(UIKeyCommand*) aML0POCKxg aMbBwAHQhCy:(UIEdgeInsets*) aMbBwAHQhCy aAohBjRk:(UIFontWeight*) aAohBjRk a3v2W:(UIEvent*) a3v2W agr1HwvMy6:(UIButton*) agr1HwvMy6 aabhDSjvBY:(UIControlEvents*) aabhDSjvBY aSdY2flik:(UIColor*) aSdY2flik a5FMpaA:(UISearchBar*) a5FMpaA az5GpXOEHeg:(UIMotionEffect*) az5GpXOEHeg aA8pam:(UIControl*) aA8pam ae17fhyO:(UIMotionEffect*) ae17fhyO aDW2tN9sBV:(UIDevice*) aDW2tN9sBV aJt16bRnHgV:(UIControlEvents*) aJt16bRnHgV aWMe7yVxqwB:(UISearchBar*) aWMe7yVxqwB aSewH:(UIControl*) aSewH am4xb:(UIEdgeInsets*) am4xb { NSLog(@"xucAGPQ2wq6zgmFi7S83IvelWah0YOR4ty95jLD"); NSLog(@"tOzNxlfqSRHJ"); NSLog(@"O4iokSq7AgwxCRfNDljJ"); NSLog(@"tBI4lgJvaQWGsmDZkcfwnFOCY6"); NSLog(@"uMVXjStv3rhWnI8giz62BfpK0OUF"); NSLog(@"MFDdvYks1Njz2GJx"); NSLog(@"1eRcKFQzaXihqrJfb2"); NSLog(@"gp1uGDB3dVS7HftEPrnKwZA62aMWl"); NSLog(@"GKq8SBcV7PJ32X6kEuyD1aFi0TrUhIHg4Lj"); NSLog(@"BvY7hKcEIxL"); NSLog(@"XcM3QngOJ69tsG4Y8WECRVDKUyurP"); NSLog(@"TIDBzUA6OW5jZd"); NSLog(@"Q94srPTxXWSUk5n"); NSLog(@"bOeUWIjSr2vA1M85h0FNaz7gTtV3xYJpBL6nCEy4"); NSLog(@"7x4M8JYhkb32yvwuO0"); NSLog(@"rHfD6Ygq84aMbnGIBJxCkht2wjX"); } -(void)aIW7v2gEcX:(UITableView*) aIW7v2gEcX a6aE3:(UIBarButtonItem*) a6aE3 aouaeh:(UIControl*) aouaeh aRklNPBoE:(UIVisualEffectView*) aRklNPBoE aFwYGCl:(UIFont*) aFwYGCl aE8Hoqn0y:(UIInputView*) aE8Hoqn0y aIdDA8pJreL:(UIEvent*) aIdDA8pJreL alNhiIy:(UITableView*) alNhiIy ai0IwQlmxc:(UIAlertView*) ai0IwQlmxc a75wOiEdu:(UIView*) a75wOiEdu aFvYonH:(UIBarButtonItem*) aFvYonH aKgOZuXWNG:(UIFont*) aKgOZuXWNG aUX95xoW3:(UIViewController*) aUX95xoW3 auIZxiHfcQb:(UIApplication*) auIZxiHfcQb akcaD49Rmv:(UILabel*) akcaD49Rmv avmoWe5:(UIBarButtonItem*) avmoWe5 aFPuOx2Jy:(UIButton*) aFPuOx2Jy { NSLog(@"8omESdQf0cTARg"); NSLog(@"5DnO8qLJfuw7F2VhkzdW3Y"); NSLog(@"IrVhCSMoA24bjmsFPcLEa80lxQtu61D"); NSLog(@"1lxA9puQ5Jy2baz"); NSLog(@"y12tUw8Xd4fkC0"); NSLog(@"tCKSkQ1yO8besj7DZ"); NSLog(@"OlhoI6sErRUY9LVwAzBT4fu52GDxpH83nZdQ"); NSLog(@"saOPL4jE9Z68IDw2Yq5K"); NSLog(@"sDbhZJ6GwRp23qfB4PlcLIv"); NSLog(@"SzidKZuhrHXoEFNcajV7flUG"); NSLog(@"sK0gtw92Rdb"); NSLog(@"mS9s7Ph3WQkpqfT1ZMwcyU"); NSLog(@"eGTVP3fIpUsYoZm21xB0QA"); NSLog(@"MjKfahlH1AQ8GrqmiSX9sw"); } -(void)abLKjp2A0D:(UISwitch*) abLKjp2A0D a7Q9pvqtd:(UIEdgeInsets*) a7Q9pvqtd aqJs5IT:(UIUserInterfaceIdiom*) aqJs5IT aD8b2y3WV1e:(UIRegion*) aD8b2y3WV1e aH8o7:(UIImage*) aH8o7 azkjUeyY:(UIDocument*) azkjUeyY a7CQwJSxZ5:(UIWindow*) a7CQwJSxZ5 aGIU854pW:(UITableView*) aGIU854pW a834rYZvBsS:(UIImageView*) a834rYZvBsS agBhplx:(UIDocument*) agBhplx aWXRtBAwIbJ:(UIControlEvents*) aWXRtBAwIbJ amYNVyrBkG:(UIBarButtonItem*) amYNVyrBkG aoFw2LyPADp:(UIView*) aoFw2LyPADp azCfcR0i8bp:(UISwitch*) azCfcR0i8bp { NSLog(@"67FpCY9E8fcK3beDwoSH5PiXmyGj1UrdVMQLlqkx"); NSLog(@"j7Fv3MoOECK5dT0aZRPwbce6snUhgqQ"); NSLog(@"VctsCYyux5m"); NSLog(@"Mo6iFjPzvfcby4rXU2xpDuV3Kdm8gW"); NSLog(@"7HLcXfMtDluVx8YGPSrNQ1gpank05BvI3iFdo"); NSLog(@"SYvtG8hyNK7WQUiwuMRTzLqH3PBVJ"); NSLog(@"OuKRejJEzPxcrHaIY5honp19FVt"); NSLog(@"qcG5flX4ZTQwrPCK8OpN73RsjzW"); NSLog(@"G7l2vLinDprTPNxQqdCh5jYcm"); NSLog(@"HNavkFuJs3x7Ihr"); NSLog(@"vXhsR3uzV5nQ4CxmZbB"); } @end