| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406 |
- //
- // MOTextTools.m
- // MiMoLive
- //
- // Created by SuperC on 2023/12/27.
- //
- #define kRtmBaseViewHeight 16.0
- #import "MOTextTools.h"
- #import "NSAttributedString+YYText.h"
- #import "UIView+YYAdd.h"
- #import "UIImage+YYAdd.h"
- #import <SDWebImage/SDWebImage.h>
- #import <YYKit/UIImageView+YYWebImage.h>
- #import <YYImage.h>
- #import "MOFanClubNameplateView.h"
- #import "UIImageView+Gift.h"
- @implementation MOTextTools
- + (NSMutableAttributedString *)creteTextWith:(MORtmEntity *)rtmEntity{
- MORtmJosnEntity *jsonEntity = (MORtmJosnEntity *)rtmEntity.data;
-
- if(jsonEntity && [jsonEntity isKindOfClass:[MORtmJosnEntity class]]){
- if(jsonEntity.content.length == 0){
- jsonEntity.content = @"";
- }
- }
- else{
- jsonEntity = [MORtmJosnEntity new];
- jsonEntity.content = @"";
- }
-
- NSString *contentStr;
- if(rtmEntity.type == MORtmChat){
- contentStr = jsonEntity.content;
- }
- else if (rtmEntity.type == MORtmEnter){
- contentStr = [NSString stringWithFormat:@"%@ %@",rtmEntity.user.username,NSLocalString(@"mimo_common_enter_room_anim_tip")];
- }
- else if (rtmEntity.type == MORoomCleanRtmTip){
- contentStr = [NSString stringWithFormat:@"%@ %@",rtmEntity.user.username,NSLocalString(@"mimo_common_live_room_clean_rtm_tip")];
- NSMutableAttributedString *tipText = [MOTextTools tipAllWhiteStringWith:contentStr];
- return tipText;
- }
- else if (rtmEntity.type == MORtmRoomTip){
- if(jsonEntity.type == 1){
- if(jsonEntity.status == 1){
- //关注
- contentStr = [NSString stringWithFormat:@"%@ %@",rtmEntity.user.username,NSLocalString(@"mimo_common_follow_room_tip")];
- }
- else{
- //取关
- contentStr = [NSString stringWithFormat:@"%@ %@",rtmEntity.user.username,NSLocalString(@"mimo_common_no_follow_room_tip")];
- }
- }
- else if (jsonEntity.type == 2){
- if(jsonEntity.status == 1){
- //胜利
- contentStr = [NSString stringWithFormat:NSLocalString(@"mimo_common_pk_room_win_tip"),rtmEntity.user.username];
- }
- else if (jsonEntity.status == 2){
- //自己投降
- contentStr = NSLocalString(@"mimo_common_pk_room_surrender_my_tip");
- }
- else if (jsonEntity.status == 3){
- //对方投降
- contentStr = NSLocalString(@"mimo_common_pk_room_surrender_other_tip");
- }
- else if (jsonEntity.status == 4){
- //平局
- contentStr = NSLocalString(@"mimo_common_pk_room_draw_tip");
- }
- else{
- //失败
- contentStr = [NSString stringWithFormat:NSLocalString(@"mimo_common_pk_room_fail_tip"),rtmEntity.user.username];
- }
-
- NSMutableAttributedString *tipText = [MOTextTools tipAllWhiteStringWith:contentStr];
- return tipText;
- }
- else if (jsonEntity.type == 3){
- if(jsonEntity.status == 1){
- //禁言
- contentStr = [NSString stringWithFormat:NSLocalString(@"mimo_common_room_silence_tip"),jsonEntity.userName];
- }
- else{
- //解除禁言
- contentStr = [NSString stringWithFormat:NSLocalString(@"mimo_common_room_no_silence_tip"),jsonEntity.userName];
- }
-
- NSMutableAttributedString *tipText = [MOTextTools tipAllWhiteStringWith:contentStr];
- return tipText;
- }
- else if (jsonEntity.type == 4){
- if(jsonEntity.status == 0){
- //主播离开
- contentStr = NSLocalString(@"mimo_anchor_short_leave_rtm_tip");
- }
- else{
- //主播回来
- contentStr = NSLocalString(@"mimo_anchor_short_leave_back_rtm_tip");
- }
- NSMutableAttributedString *tipText = [MOTextTools tipAllWhiteStringWith:contentStr];
- return tipText;
- }
- else{
- contentStr = [NSString stringWithFormat:@"%@: %@",rtmEntity.user.username,jsonEntity.content];
- }
- }
- else if (rtmEntity.type == MOLikeComboTip){
- if(jsonEntity.type == 1){
- contentStr = [NSString stringWithFormat:@"%@ %@",rtmEntity.user.username,NSLocalString(@"mimo_common_like_first_tip")];
- NSMutableAttributedString *tipText = [MOTextTools tipAllWhiteStringWith:contentStr];
- return tipText;
- }
- }
- else if (rtmEntity.type == MORoomTipTwo){//房间通用提示 - V2
- if(jsonEntity.type == 1){//添加管理员
- NSString *contentStr = [NSString stringWithFormat:NSLocalString(@"mimo_2_live_rtm_manager_tip_1"),jsonEntity.userName];
- NSMutableAttributedString *tipText = [MOTextTools base_colorfulStringWith:contentStr AndNameStr:jsonEntity.userName];
- NSString *fanClubStr = NSLocalString(@"mimo_2_live_rtm_manager_tip_2");
- if(fanClubStr.length != 0){
- NSRange redRange = [contentStr rangeOfString:fanClubStr];
- if(redRange.location != NSNotFound){
- // 将最后三个字符的颜色设置为红色
- [tipText addAttribute:NSForegroundColorAttributeName value:kBaseTextHightlightColor_1 range:redRange];
- }
- }
- return tipText;
- }
- }
- else if (rtmEntity.type == MORtmGiftEndNum){
- NSMutableAttributedString *giftNumText = [MOTextTools creteGiftNumTextWith:rtmEntity];
- return giftNumText;
- }
- else if (rtmEntity.type == SystemTipGetRed){
- NSMutableAttributedString *giftNumText = [MOTextTools creteRedTipWith:rtmEntity];
- return giftNumText;
- }
- else if (rtmEntity.type == SystemOrder){
- if(jsonEntity.type == 9 || jsonEntity.type == 10 || jsonEntity.type == 11){
- NSMutableAttributedString *giftNumText = [MOTextTools creteRedTipWith:rtmEntity];
- return giftNumText;
- }
- else if (jsonEntity.type == 24){//加入粉丝团
- NSString *contentStr = [NSString stringWithFormat:NSLocalString(@"mimo_2_live_rtm_fan_club_tip_1"),jsonEntity.roomUser.nickname];
- NSMutableAttributedString *tipText = [MOTextTools base_colorfulStringWith:contentStr AndNameStr:jsonEntity.roomUser.nickname];
- NSString *fanClubStr = NSLocalString(@"mimo_2_live_rtm_fan_club_tip_2");
- if(fanClubStr.length != 0){
- NSRange redRange = [contentStr rangeOfString:fanClubStr];
- if(redRange.location != NSNotFound){
- // 将最后三个字符的颜色设置为红色
- [tipText addAttribute:NSForegroundColorAttributeName value:kBaseTextHightlightColor_1 range:redRange];
- }
- }
- return tipText;
- }
- else if (jsonEntity.type == 26){//用户升级通知
- MORtmUserLevelUpgrade *userLevel = jsonEntity.levelNotice;
- NSMutableAttributedString *baseAttri = [[NSMutableAttributedString alloc] initWithString:@" "];
- NSMutableAttributedString *vipAttri = [self toAddLevelInfoWith:baseAttri And:userLevel.afterLevel];
- NSString *contentStr = [NSString stringWithFormat:NSLocalString(@"mimo_2_live_rtm_level_up_1"),jsonEntity.roomUser.nickname];
- NSMutableAttributedString *tipText = [MOTextTools base_colorfulStringWith:contentStr AndNameStr:jsonEntity.roomUser.nickname];
- // 设置字体大小的属性
- [tipText addAttribute:NSFontAttributeName value:MOTextLabelFont range:NSMakeRange(0, tipText.length)];
- [tipText appendAttributedString:vipAttri];
- return tipText;
- } else if (jsonEntity.type == 33) {//盲盒礼物中奖推送
- return [self createBlindBoxGiftDrawTextWith:jsonEntity];
- }
- }
- else if (rtmEntity.type == MOChangeRoomType){
- if(jsonEntity.type == 2){
- contentStr = NSLocalString(@"mimo_ticket_change_success_tip");
- NSMutableAttributedString *tipText = [MOTextTools tipAllWhiteStringWith:contentStr];
- return tipText;
- }
- }
- else if (rtmEntity.type == SystemTipNormalBlue || rtmEntity.type == SystemTipBlindBox){
- contentStr = jsonEntity.content;
- NSMutableAttributedString *tipText = [MOTextTools tipAllWhiteStringWith:contentStr];
- return tipText;
- }
- else if (rtmEntity.type == SystemTipHitDiamond){
- NSMutableAttributedString *tipText = [MOTextTools creteTheHitDiamondTipWith:rtmEntity];
- return tipText;
- }
-
- NSMutableAttributedString *plainText = [MOTextTools base_colorfulStringWith:contentStr AndNameStr:rtmEntity.user.username];
-
- if(jsonEntity.atNameList.length != 0){
- plainText = [self add_atColorfulStringWith:plainText AndAtString:jsonEntity.atNameList];
- [plainText addAttribute:NSFontAttributeName value:MOTextLabelFont range:NSMakeRange(0, plainText.length)];
- return plainText;
- }
-
- if(rtmEntity.type == MORtmChat){
- [plainText addAttribute:NSFontAttributeName value:MOTextLabelFont range:NSMakeRange(0, plainText.length)];
- return plainText;
- }
-
- if(rtmEntity.type == MORtmEnter){
- plainText = [MOTextTools tipAllWhiteStringWith:contentStr];
- }
-
- if((rtmEntity.type == MORtmRoomTip && jsonEntity.status == 1)||
- rtmEntity.type == MORoomCleanRtmTip){
- plainText = [MOTextTools tipAllWhiteStringWith:contentStr];
- }
- // 设置字体大小的属性
- [plainText addAttribute:NSFontAttributeName value:MOTextLabelFont range:NSMakeRange(0, plainText.length)];
-
- //加粉丝团
- [self toAddFanClubInfoWith:plainText And:rtmEntity.user.fans];
-
- [plainText insertAttributedString:[[NSAttributedString alloc] initWithString:@" "] atIndex:0];
-
- //加勋章
- // [self toAddMedalInfoWith:plainText And:rtmEntity.user.medalCodeList];
- //加vip
- [self toAddVipInfoWith:plainText And:rtmEntity.user.vip.type];
-
- //加等级
- [self toAddLevelInfoWith:plainText And:rtmEntity.user.level];
- [plainText addAttribute:NSFontAttributeName value:MOTextLabelFont range:NSMakeRange(0, plainText.length)];
-
- return plainText;
- }
- //盲盒玩法 中奖礼物
- + (NSMutableAttributedString *)createBlindBoxGiftDrawTextWith:(MORtmJosnEntity *)jsonEntity {
- MORtmBlindboxDrawResult *result = jsonEntity.blindboxDrawResult;
-
- NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] init];
-
- if (result.isShowGift) {//礼物
-
- NSString *prefix = nil;
- NSString *suffix = nil;
- if (result.noticeType == 1) {
- prefix = [NSString stringWithFormat:@"%@%@", result.nickname, NSLocalString(@"C20017-1")];
- suffix = NSLocalString(@"C20017-2");
- } else if (result.noticeType == 2) {
- prefix = [NSString stringWithFormat:@"%@%@", result.nickname, NSLocalString(@"C20018-1")];
- suffix = @"";
- } else if (result.noticeType == 3) {
- prefix = [NSString stringWithFormat:@"%@%@", result.nickname, NSLocalString(@"C20019-1")];
- suffix = @"";
- }
- // 前缀
- [attrStr appendAttributedString:[[NSAttributedString alloc] initWithString:prefix
- attributes:@{NSForegroundColorAttributeName: UIColor.whiteColor,
- NSFontAttributeName: MOTextLabelFont}]];
-
- if (result.nickname.length > 0) {
- NSRange nameRange = [prefix rangeOfString:result.nickname];
- if (nameRange.location != NSNotFound) {
- [attrStr addAttribute:NSForegroundColorAttributeName value:kBaseTextHightlightColor_1 range:nameRange];
- }
- }
-
- for (MORtmBlindboxGift *gift in result.list) {
- MOGiftInfo *giftInfo = [[MOSvgaSourceManage shareManager] getGiftInfoWithCode:gift.giftCode];
- if(giftInfo){
- UIImage *cacheImage = [[SDImageCache giftCache] imageFromDiskCacheForKey:giftInfo.giftPath];
- if(cacheImage){
- CGSize cacheSize;
- cacheImage = [cacheImage imageByResizeToSize:CGSizeMake(cacheImage.size.width / 2.0, cacheImage.size.height / 2.0) contentMode:UIViewContentModeScaleAspectFit];
-
- NSTextAttachment *vipAttachment;
- vipAttachment = [[NSTextAttachment alloc] init];
- vipAttachment.image = cacheImage;
- //字体行高
- UIFont *font = MOTextLabelFont;
- CGFloat attachmentHeight = font.lineHeight;
- CGFloat imgSizeHeight = GetParamNotZero(cacheImage.size.height);
- CGFloat attachmentWidth = attachmentHeight * cacheImage.size.width/ imgSizeHeight;
- vipAttachment.bounds = CGRectMake(0, (font.capHeight-font.lineHeight)/2, attachmentWidth, attachmentHeight);
- cacheSize = CGSizeMake(attachmentWidth, attachmentHeight);
-
- NSMutableAttributedString *cacheImageAttri = [NSMutableAttributedString attachmentStringWithContent:cacheImage contentMode:UIViewContentModeScaleAspectFit attachmentSize:cacheSize alignToFont:MOTextLabelFont alignment:YYTextVerticalAlignmentCenter];
- [attrStr appendAttributedString:cacheImageAttri];
-
- NSString *giftNumStr = [NSString stringWithFormat:@" x%zd",gift.amount];
- NSMutableAttributedString *giftText;
- giftText = [[NSMutableAttributedString alloc] initWithString:giftNumStr attributes:@{NSForegroundColorAttributeName:[MOTools colorWithHexString:@"#F5E87F" alpha:1.0], NSFontAttributeName:MOTextLabelFont}];
- [attrStr appendAttributedString:giftText];
- }
- else{
- NSMutableAttributedString *giftText;
- NSString *giftNumStr = [NSString stringWithFormat:@" %@ x%zd",giftInfo.giftName,gift.amount];
- giftText = [[NSMutableAttributedString alloc] initWithString:giftNumStr attributes:@{NSForegroundColorAttributeName:[MOTools colorWithHexString:@"#F5E87F" alpha:1.0], NSFontAttributeName:MOTextLabelFont}];
- [attrStr appendAttributedString:giftText];
- }
- }
- else{
- NSMutableAttributedString *giftText;
- NSString *giftNumStr = [NSString stringWithFormat:@" x%zd",gift.amount];
- giftText = [[NSMutableAttributedString alloc] initWithString:giftNumStr attributes:@{NSForegroundColorAttributeName:[MOTools colorWithHexString:@"#F5E87F" alpha:1.0]}];
-
- [attrStr appendAttributedString:giftText];
- }
- }
-
- if (suffix.length > 0) {
- // 后缀
- [attrStr appendAttributedString:[[NSAttributedString alloc] initWithString:suffix
- attributes:@{NSForegroundColorAttributeName: UIColor.whiteColor,
- NSFontAttributeName: MOTextLabelFont}]];
- }
- } else {//装扮
-
- NSString *prefix = nil;
- NSString *suffix = nil;
- if (result.noticeType == 1) {
- prefix = [NSString stringWithFormat:@"%@%@", result.nickname, [NSString stringWithFormat:NSLocalString(@"C20020-1"), NSLocalString(@"C20020-0")]];
- suffix = [NSString stringWithFormat:NSLocalString(@"C20020-2"), NSLocalString(@"C20020-0")];
- } else if (result.noticeType == 2) {
- prefix = [NSString stringWithFormat:@"%@%@", result.nickname, [NSString stringWithFormat:NSLocalString(@"C20021-1"), NSLocalString(@"C20020-0")]];
- suffix = [NSString stringWithFormat:NSLocalString(@"C20021-2"), NSLocalString(@"C20020-0")];
- } else if (result.noticeType == 3) {
- prefix = [NSString stringWithFormat:@"%@%@", result.nickname, [NSString stringWithFormat:NSLocalString(@"C20022-1"), NSLocalString(@"C20020-0")]];
- suffix = [NSString stringWithFormat:NSLocalString(@"C20022-2"), NSLocalString(@"C20020-0")];
- }
-
- // 前缀
- [attrStr appendAttributedString:[[NSAttributedString alloc] initWithString:prefix
- attributes:@{NSForegroundColorAttributeName: UIColor.whiteColor,
- NSFontAttributeName: MOTextLabelFont}]];
-
- if (result.nickname.length > 0) {
- NSRange nameRange = [prefix rangeOfString:result.nickname];
- if (nameRange.location != NSNotFound) {
- [attrStr addAttribute:NSForegroundColorAttributeName value:kBaseTextHightlightColor_1 range:nameRange];
- }
- }
-
- NSString *propString = [self createBlindBoxDeawResultPropString:result.propNotices];
-
- if (propString.length > 0) {
- [attrStr appendAttributedString:[[NSAttributedString alloc] initWithString:propString
- attributes:@{NSForegroundColorAttributeName:kBaseTextHightlightColor_1,
- NSFontAttributeName: MOTextLabelFont}]];
-
- NSRange nameRange = [prefix rangeOfString:NSLocalString(@"C20020-0")];
- if (nameRange.location != NSNotFound) {
- [attrStr addAttribute:NSForegroundColorAttributeName value:kBaseTextHightlightColor_1 range:nameRange];
- }
- }
-
- if (suffix.length > 0) {
- // 后缀开始位置
- NSUInteger startLocation = attrStr.length;
-
- [attrStr appendAttributedString:[[NSAttributedString alloc] initWithString:suffix
- attributes:@{NSForegroundColorAttributeName: UIColor.whiteColor,
- NSFontAttributeName: MOTextLabelFont}]];
-
- NSRange nameRangeInSuffix = [suffix rangeOfString:NSLocalString(@"C20020-0")];
- if (nameRangeInSuffix.location != NSNotFound) {
- NSRange adjustedRange = NSMakeRange(startLocation + nameRangeInSuffix.location, nameRangeInSuffix.length);
- [attrStr addAttribute:NSForegroundColorAttributeName value:kBaseTextHightlightColor_1 range:adjustedRange];
- }
- }
- }
- return attrStr;
- }
- + (NSString *)createBlindBoxDeawResultPropString:(NSArray<NSString *> *)propNotices {
- NSMutableString *propString = [NSMutableString string];
- [propNotices enumerateObjectsUsingBlock:^(NSString * _Nonnull notice, NSUInteger idx, BOOL * _Nonnull stop) {
- [propString appendString:notice];
- if (idx != (propNotices.count - 1)) {
- [propString appendString:@"、"];
- }
- }];
- return propString;
- }
- //系统消息 26的顶部提示
- + (NSMutableAttributedString *)createTheLevelUpNoticeWith:(MORtmEntity *)rtmEntity{
- MORtmJosnEntity *jsonEntity = (MORtmJosnEntity *)rtmEntity.data;
-
- if(jsonEntity && [jsonEntity isKindOfClass:[MORtmJosnEntity class]]){
- if(jsonEntity.content.length == 0){
- jsonEntity.content = @"";
- }
- }
- else{
- jsonEntity = [MORtmJosnEntity new];
- jsonEntity.content = @"";
- }
-
- MORtmUserLevelUpgrade *userLevel = jsonEntity.levelNotice;
- NSMutableAttributedString *baseAttri = [[NSMutableAttributedString alloc] initWithString:@" "];//初始化
-
- //第一个
- NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithString:NSLocalString(@"mimo_2_live_rtm_level_up_2")];//顶部
- [title addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0, title.length)];
-
- //头像
- if(jsonEntity.roomUser.avatar.length > 0){
- [self addTheUserHeadWith:title And:jsonEntity.roomUser.avatar];
- }
-
- //后面
- NSString *contentStr = [NSString stringWithFormat:NSLocalString(@"mimo_2_live_rtm_level_up_3"),jsonEntity.roomUser.nickname];
- NSMutableAttributedString *tipText = [MOTextTools base_colorfulStringWith:contentStr AndNameStr:jsonEntity.roomUser.nickname];
- [title appendAttributedString:tipText];
-
- // 设置字体大小的属性
- [title addAttribute:NSFontAttributeName value:MOTextLabelFont range:NSMakeRange(0, title.length)];
-
- //等级
- NSMutableAttributedString *vipAttri = [self toAddLevelInfoWith:baseAttri And:userLevel.afterLevel];//等级
- [title appendAttributedString:vipAttri];
-
- return title;
- }
- + (NSMutableAttributedString *)addTheUserHeadWith:(NSMutableAttributedString *)contentStr And:(NSString *)headUrl{
-
- if(headUrl.length == 0){
- return contentStr;
- }
-
- //这里调整的话, 请同时调整 MOBaseLevelView
- CGFloat levelWidth = 17;
- CGFloat levelLabelX = 17.0;
- UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, levelWidth, levelWidth)];
- bgView.backgroundColor = [UIColor clearColor];
- bgView.layer.cornerRadius = levelWidth / 2.0;
- bgView.layer.masksToBounds = YES;
-
- YYAnimatedImageView *levelImg = [[YYAnimatedImageView alloc] init];
- levelImg.frame = CGRectMake(0.0, 0.0, levelWidth, levelWidth);
- levelImg.contentMode = UIViewContentModeScaleAspectFit;
- NSURL *url = [NSURL URLWithString:headUrl];
- [levelImg setImageWithURL:url placeholder:[UIImage imageNamed:@"icon_mine_placeHolder"]];
- [bgView addSubview:levelImg];
- CGSize viewSize = bgView.size;
-
- NSMutableAttributedString *levelImgAttri = [NSMutableAttributedString attachmentStringWithContent:bgView contentMode:UIViewContentModeScaleAspectFit attachmentSize:viewSize alignToFont:MOTextLabelFont alignment:YYTextVerticalAlignmentCenter];
- [levelImgAttri appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
- [contentStr appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
- [contentStr appendAttributedString:levelImgAttri];
-
- return contentStr;
- }
- ///组建 - 普通聊天头部
- + (NSMutableAttributedString *)creteTitleTextWith:(MORtmEntity *)rtmEntity{
- MORtmJosnEntity *jsonEntity = (MORtmJosnEntity *)rtmEntity.data;
-
- if(jsonEntity && [jsonEntity isKindOfClass:[MORtmJosnEntity class]]){
- if(jsonEntity.content.length == 0){
- jsonEntity.content = @"";
- }
- }
- else{
- jsonEntity = [MORtmJosnEntity new];
- jsonEntity.content = @"";
- }
-
- NSString *contentStr;
- if(rtmEntity.type == MORtmChat){
- if(rtmEntity.user.username.length == 0){
- contentStr = @"";
- }
- else{
- contentStr = rtmEntity.user.username;
- }
- }
-
- NSMutableAttributedString *plainText = [MOTextTools base_colorfulStringWith:contentStr AndNameStr:rtmEntity.user.username];
-
- //加粉丝团
- [self toAddFanClubInfoWith:plainText And:rtmEntity.user.fans];
-
- [plainText insertAttributedString:[[NSAttributedString alloc] initWithString:@" "] atIndex:0];
-
- //加vip
- [self toAddVipInfoWith:plainText And:rtmEntity.user.vip.type];
-
- //加等级
- [self toAddLevelInfoWith:plainText And:rtmEntity.user.level];
-
- // 设置字体大小的属性
- [plainText addAttribute:NSFontAttributeName value:MOTextLabelFont range:NSMakeRange(0, plainText.length)];
-
- return plainText;
- }
- + (NSMutableAttributedString *)addTempGifWith:(NSMutableAttributedString *)contentStr{
- UIView *giftBgView = [[UIView alloc] init];
- giftBgView.backgroundColor = [UIColor redColor];
-
- YYImage *giftImg = [YYImage imageNamed:@"gif_icon_explore.gif"];
- YYAnimatedImageView *imageView = [[YYAnimatedImageView alloc] initWithImage:giftImg];
- imageView.frame = CGRectMake(0.0, 0.0, 16.0, 16.0);
-
- UILabel *levelLab = [[UILabel alloc] init];
- levelLab.text = @"66";
- levelLab.font = [MOTextTools getTheFontWithSize:12.0 AndFontName:kNormalTitleFontStr];
- levelLab.textColor = [MOTools colorWithHexString:@"#FFFFFF" alpha:1.0];
- levelLab.frame = CGRectMake(0.0, 0.0, 16.0, 16.0);
-
- [giftBgView addSubview:imageView];
- [giftBgView addSubview:levelLab];
- giftBgView.frame = CGRectMake(0.0, 0.0, 16.0, 16.0);
- CGSize viewSize = giftBgView.frame.size;
-
- NSMutableAttributedString *levelImgAttri = [NSMutableAttributedString attachmentStringWithContent:giftBgView contentMode:UIViewContentModeScaleAspectFit attachmentSize:viewSize alignToFont:MOTextLabelFont alignment:YYTextVerticalAlignmentCenter];
- [contentStr appendAttributedString:levelImgAttri];
- return contentStr;
- }
- + (NSMutableAttributedString *)creteEnterTextWith:(MORtmEntity *)rtmEntity{
- MORtmJosnEntity *jsonEntity = (MORtmJosnEntity *)rtmEntity.data;
-
- if(jsonEntity && [jsonEntity isKindOfClass:[MORtmJosnEntity class]]){
- if(jsonEntity.content.length == 0){
- jsonEntity.content = @"";
- }
- }
- else{
- jsonEntity = [MORtmJosnEntity new];
- jsonEntity.content = @"";
- }
-
- NSString *contentStr;
- if(rtmEntity.type == MORtmChat){
- contentStr = [NSString stringWithFormat:@"%@: %@",rtmEntity.user.username,jsonEntity.content];
- }
- else if (rtmEntity.type == MORtmEnter){
- contentStr = rtmEntity.user.username;
- }
-
- NSMutableAttributedString *plainText = [[NSMutableAttributedString alloc] initWithString:contentStr];
- // 设置字体大小的属性
- [plainText addAttribute:NSFontAttributeName value:[MOTextTools regularFont:10.0] range:NSMakeRange(0, plainText.length)];
-
- NSRange redRange = [contentStr rangeOfString:rtmEntity.user.username];
- if(redRange.location != NSNotFound){
- // 将最后三个字符的颜色设置为红色
- [plainText addAttribute:NSFontAttributeName value:[MOTextTools mediumFont:10.0] range:redRange];
- }
-
- //加vip
- if(rtmEntity.user.vip.type > 0){
- [self toAddSmallVipInfoWith:plainText And:rtmEntity.user.vip.type AndHeight:14.0];
- }
-
- //加等级
- [self toAddSmallLevelInfoWith:plainText And:rtmEntity.user.level AndHeight:14.0 AndAlignToFont:[MOTextTools regularFont:10.0]];
-
- return plainText;
- }
- //根据Rtm消息, 生成礼物数量NSMutableAttributedString
- + (NSMutableAttributedString *)creteGiftNumTextWith:(MORtmEntity *)rtmEntity{
- MORtmJosnEntity *jsonEntity = (MORtmJosnEntity *)rtmEntity.data;
-
- if(jsonEntity && [jsonEntity isKindOfClass:[MORtmJosnEntity class]]){
- if(jsonEntity.content.length == 0){
- jsonEntity.content = @"";
- }
- }
- else{
- jsonEntity = [MORtmJosnEntity new];
- jsonEntity.content = @"";
- }
-
- NSString *contentStr = [NSString stringWithFormat:@"%@ Send gift ",rtmEntity.user.username];
-
- NSMutableAttributedString *plainText = [MOTextTools colorfulStringWith:contentStr AndNameStr:rtmEntity.user.username];
-
- NSMutableAttributedString *giftText;
-
- //礼物
- MOGiftInfo *giftInfo = [[MOSvgaSourceManage shareManager] getGiftInfoWithCode:jsonEntity.code];
- if(giftInfo){
- UIImage *cacheImage = [[SDImageCache giftCache] imageFromDiskCacheForKey:giftInfo.giftPath];
- if(cacheImage){
- CGSize cacheSize;
- cacheImage = [cacheImage imageByResizeToSize:CGSizeMake(cacheImage.size.width / 2.0, cacheImage.size.height / 2.0) contentMode:UIViewContentModeScaleAspectFit];
-
- NSTextAttachment *vipAttachment;
- vipAttachment = [[NSTextAttachment alloc] init];
- vipAttachment.image = cacheImage;
- //字体行高
- UIFont *font = MOTextLabelFont;
- CGFloat attachmentHeight = font.lineHeight;
- CGFloat imgSizeHeight = GetParamNotZero(cacheImage.size.height);
- CGFloat attachmentWidth = attachmentHeight * cacheImage.size.width/ imgSizeHeight;
- vipAttachment.bounds = CGRectMake(0, (font.capHeight-font.lineHeight)/2, attachmentWidth, attachmentHeight);
- cacheSize = CGSizeMake(attachmentWidth, attachmentHeight);
-
- NSMutableAttributedString *cacheImageAttri = [NSMutableAttributedString attachmentStringWithContent:cacheImage contentMode:UIViewContentModeScaleAspectFit attachmentSize:cacheSize alignToFont:MOTextLabelFont alignment:YYTextVerticalAlignmentCenter];
- // NSMutableAttributedString *cacheImageAttri = [[NSAttributedString attributedStringWithAttachment:vipAttachment] mutableCopy];
- [plainText appendAttributedString:cacheImageAttri];
-
- NSString *giftNumStr = [NSString stringWithFormat:@" x%zd",jsonEntity.count];
- giftText = [[NSMutableAttributedString alloc] initWithString:giftNumStr attributes:@{NSForegroundColorAttributeName:[MOTools colorWithHexString:@"#EFE85C" alpha:1.0]}];
-
- [plainText appendAttributedString:giftText];
- }
- else{
- NSString *giftNumStr = [NSString stringWithFormat:@" %@ x%zd",giftInfo.giftName,jsonEntity.count];
- giftText = [[NSMutableAttributedString alloc] initWithString:giftNumStr attributes:@{NSForegroundColorAttributeName:[MOTools colorWithHexString:@"#EFE85C" alpha:1.0]}];
-
- [plainText appendAttributedString:giftText];
- }
- }
- else{
- NSString *giftNumStr = [NSString stringWithFormat:@" x%zd",jsonEntity.count];
- giftText = [[NSMutableAttributedString alloc] initWithString:giftNumStr attributes:@{NSForegroundColorAttributeName:[MOTools colorWithHexString:@"#EFE85C" alpha:1.0]}];
-
- [plainText appendAttributedString:giftText];
- }
- //加粉丝团
- [self toAddFanClubInfoWith:plainText And:rtmEntity.user.fans];
-
- [plainText insertAttributedString:[[NSAttributedString alloc] initWithString:@" "] atIndex:0];
-
- //加勋章
- // [self toAddMedalInfoWith:plainText And:rtmEntity.user.medalCodeList];
-
- //加vip
- [self toAddVipInfoWith:plainText And:rtmEntity.user.vip.type];
-
- //加等级
- [self toAddLevelInfoWith:plainText And:rtmEntity.user.level];
-
- // 设置字体大小的属性
- [plainText addAttribute:NSFontAttributeName value:MOTextLabelFont range:NSMakeRange(0, plainText.length)];
- return plainText;
- }
- + (NSMutableAttributedString *)creteTheHitDiamondTipWith:(MORtmEntity *)entity{
- MORtmJosnEntity *jsonEntity = (MORtmJosnEntity *)entity.data;
- NSString *contentStr = [NSString stringWithFormat:NSLocalString(@"C40002_2"),jsonEntity.hitDiamond];
- NSMutableAttributedString *contentAttri = [[NSMutableAttributedString alloc] initWithString:contentStr];
- [self toAddHitDiamondWith:contentAttri];
- NSAttributedString *tipOne = [[NSAttributedString alloc] initWithString:NSLocalString(@"C40002_1")];
- [contentAttri insertAttributedString:tipOne atIndex:0];
-
- [contentAttri addAttribute:NSForegroundColorAttributeName value:[MOTools colorWithHexString:@"#FFFFFF" alpha:1.0] range:NSMakeRange(0, contentAttri.length)];
-
- NSString *userName = entity.user.username;
- if(userName.length == 0){
- userName = @" ";
- }
- NSAttributedString *nameAttri = [[NSAttributedString alloc] initWithString:userName attributes:@{NSForegroundColorAttributeName:kBaseTextHightlightColor_1}];
- [contentAttri insertAttributedString:[[NSAttributedString alloc] initWithString:@" "] atIndex:0];
- [contentAttri insertAttributedString:nameAttri atIndex:0];
-
- //加粉丝团
- [self toAddFanClubInfoWith:contentAttri And:entity.user.fans];
-
- [contentAttri insertAttributedString:[[NSAttributedString alloc] initWithString:@" "] atIndex:0];
-
- //加vip
- [self toAddVipInfoWith:contentAttri And:entity.user.vip.type];
-
- //加等级
- [self toAddLevelInfoWith:contentAttri And:entity.user.level];
-
- [contentAttri addAttribute:NSFontAttributeName value:MOTextLabelFont range:NSMakeRange(0, contentAttri.length)];
-
- return contentAttri;
-
- }
- + (NSMutableAttributedString *)toAddHitDiamondWith:(NSMutableAttributedString *)contentStr{
-
- CGFloat theBaseViewHeight = kRtmBaseViewHeight - 1.0;
-
- UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, theBaseViewHeight, theBaseViewHeight)];
- bgView.backgroundColor = [UIColor clearColor];
- UIImageView *medalImg = [[UIImageView alloc] init];
- medalImg.frame = CGRectMake(0.0, 0.0, theBaseViewHeight, theBaseViewHeight);
- medalImg.contentMode = UIViewContentModeScaleAspectFit;
- [medalImg setImage:[UIImage imageNamed:@"v_2_top_zuan_24"]];
- [bgView addSubview:medalImg];
-
- NSMutableAttributedString *vipImgAttri = [NSMutableAttributedString attachmentStringWithContent:bgView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(theBaseViewHeight, theBaseViewHeight) alignToFont:MOTextLabelFont alignment:YYTextVerticalAlignmentCenter];
- [vipImgAttri appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
- [contentStr insertAttributedString:[vipImgAttri copy] atIndex:0];
- return contentStr;
- }
- + (NSMutableAttributedString *)creteRedTipWith:(MORtmEntity *)rtmEntity{
- MORtmJosnEntity *jsonEntity = (MORtmJosnEntity *)rtmEntity.data;
-
- NSString *contentStr;
- if(jsonEntity.type == 9 || jsonEntity.type == 10){
- contentStr = [NSString stringWithFormat:NSLocalString(@"mimo_red_packet_send_red_rtm_tip"),jsonEntity.redEnvelope.senderNickname];
- }
- else if (jsonEntity.type == 11){
- contentStr = [NSString stringWithFormat:NSLocalString(@"mimo_red_packet_recenved_red_rtm_tip")];
- }
- else{
- contentStr = [NSString stringWithFormat:NSLocalString(@"mimo_red_packet_get_red_rtm_tip"),jsonEntity.redSendName];
- }
-
- NSMutableAttributedString *plainText;
-
- if(jsonEntity.type == 9 || jsonEntity.type == 10 ){
-
- plainText = [MOTextTools base_colorfulStringWith:contentStr AndNameStr:jsonEntity.redEnvelope.senderNickname AndBaseColor:@"#FFFFFF" AndNameColor:@"#19FFB2"];
- }
- else if (rtmEntity.type == SystemTipGetRed){
- plainText = [MOTextTools base_colorfulStringWith:contentStr AndNameStr:jsonEntity.redSendName AndBaseColor:@"#FFFFFF" AndNameColor:@"#19FFB2"];
- }
- else{
- plainText = [MOTextTools tipAllWhiteStringWith:contentStr];
- }
-
- [plainText addAttribute:NSFontAttributeName value:MOTextLabelFont range:NSMakeRange(0, plainText.length)];
- [plainText appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
-
- if(!(jsonEntity.type == 9 || jsonEntity.type == 10)){
- //非发红包
- UIImage *redImg = [UIImage imageNamed:@"icon_red_rtm_tip"];
- redImg = [redImg imageByResizeToSize:CGSizeMake(18.0, 18.0) contentMode:UIViewContentModeScaleAspectFit];
- NSTextAttachment *redAttachment;
- if(redImg){
- CGSize redSize;
- redAttachment = [[NSTextAttachment alloc] init];
- redAttachment.image = redImg;
- //字体行高
- UIFont *font = MOTextLabelFont;
- CGFloat attachmentHeight = font.lineHeight;
- CGFloat imgSizeHeight = GetParamNotZero(redImg.size.height);
- CGFloat attachmentWidth = attachmentHeight * redImg.size.width/ imgSizeHeight;
- redAttachment.bounds = CGRectMake(0, (font.capHeight-font.lineHeight)/2, attachmentWidth, attachmentHeight);
- redSize = CGSizeMake(attachmentWidth, attachmentHeight);
-
- //生成NSAttributedString
- NSMutableAttributedString *redImgAttri = [NSMutableAttributedString attachmentStringWithContent:redImg contentMode:UIViewContentModeScaleAspectFit attachmentSize:redSize alignToFont:MOTextLabelFont alignment:YYTextVerticalAlignmentCenter];
- // NSMutableAttributedString *redImgAttri = [[NSAttributedString attributedStringWithAttachment:redAttachment] mutableCopy];
-
- [redImgAttri appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
- [plainText appendAttributedString:[redImgAttri copy]];
- }
-
- UIImage *rightImg = [UIImage imageNamed:@"icon_rtm_right"];
- rightImg = [rightImg imageByResizeToSize:CGSizeMake(8.0, 6.0) contentMode:UIViewContentModeScaleAspectFit];
- NSTextAttachment *rightAttachment;
- if(rightImg){
- CGSize rightSize;
- rightAttachment = [[NSTextAttachment alloc] init];
- rightAttachment.image = rightImg;
- //字体行高
- UIFont *font = MOTextLabelFont;
- rightAttachment.bounds = CGRectMake(0, 0, 8.0, 6.0);
- rightSize = CGSizeMake(8.0, 6.0);
-
- //生成NSAttributedString
- NSMutableAttributedString *rightImgAttri = [NSMutableAttributedString attachmentStringWithContent:rightImg contentMode:UIViewContentModeScaleAspectFit attachmentSize:rightSize alignToFont:MOTextLabelFont alignment:YYTextVerticalAlignmentCenter];
- // NSMutableAttributedString *rightImgAttri = [[NSAttributedString attributedStringWithAttachment:rightAttachment] mutableCopy];
-
- [rightImgAttri appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
- [plainText appendAttributedString:[rightImgAttri copy]];
- }
- }
- return plainText;
- }
- + (NSMutableAttributedString *)toAddVipInfoWith:(NSMutableAttributedString *)contentStr And:(NSInteger)vipType{
-
- CGFloat theBaseViewHeight = kRtmBaseViewHeight - 1.0;
-
- if(vipType != 0){
- //VIP 对象
- MOBaseVips *vipObject = [[MOSvgaSourceManage shareManager] toGetTheVipObjectWith:vipType];
- if(vipObject){
- UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, theBaseViewHeight, theBaseViewHeight)];
- bgView.backgroundColor = [UIColor clearColor];
- YYAnimatedImageView *medalImg = [[YYAnimatedImageView alloc] init];
- medalImg.frame = CGRectMake(0.0, 0.0, theBaseViewHeight, theBaseViewHeight);
- medalImg.contentMode = UIViewContentModeScaleAspectFit;
-
- NSString *urlStr = vipObject.thumbnail;
- NSURL *url = [NSURL URLWithString:urlStr];
- [medalImg setImageWithURL:url placeholder:nil];
- [bgView addSubview:medalImg];
-
- NSMutableAttributedString *vipImgAttri = [NSMutableAttributedString attachmentStringWithContent:bgView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(theBaseViewHeight, theBaseViewHeight) alignToFont:MOTextLabelFont alignment:YYTextVerticalAlignmentCenter];
- [vipImgAttri appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
- [contentStr insertAttributedString:[vipImgAttri copy] atIndex:0];
- }
- else{
- //旧版 VIP 静态图
- UIImage *vipImg = [MOTextTools getVipIconWith:vipType];
- NSTextAttachment *vipAttachment;
- if(vipImg){
- CGSize vipSize;
- vipAttachment = [[NSTextAttachment alloc] init];
- vipAttachment.image = vipImg;
- //字体行高
- UIFont *font = MOTextLabelFont;
- CGFloat attachmentHeight = font.lineHeight;
- CGFloat imgSizeHeight = GetParamNotZero(vipImg.size.height);
- CGFloat attachmentWidth = attachmentHeight * vipImg.size.width/ imgSizeHeight;
- vipAttachment.bounds = CGRectMake(0, (font.capHeight-font.lineHeight)/2, attachmentWidth, attachmentHeight);
- vipSize = CGSizeMake(attachmentWidth, attachmentHeight);
-
- NSMutableAttributedString *vipImgAttri = [NSMutableAttributedString attachmentStringWithContent:vipImg contentMode:UIViewContentModeScaleAspectFit attachmentSize:vipSize alignToFont:MOTextLabelFont alignment:YYTextVerticalAlignmentCenter];
- //生成NSAttributedString
- // NSMutableAttributedString *vipImgAttri = [[NSAttributedString attributedStringWithAttachment:vipAttachment] mutableCopy];
-
- [vipImgAttri appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
- [contentStr insertAttributedString:[vipImgAttri copy] atIndex:0];
- }
- }
- }
- return contentStr;
- }
- + (NSMutableAttributedString *)toAddSmallVipInfoWith:(NSMutableAttributedString *)contentStr And:(NSInteger)vipType AndHeight:(CGFloat)viewHeight{
-
- CGFloat theBaseViewHeight = 14;
- if(viewHeight > 0){
- theBaseViewHeight = viewHeight;
- }
-
- if(vipType != 0){
- //VIP 对象
- MOBaseVips *vipObject = [[MOSvgaSourceManage shareManager] toGetTheVipObjectWith:vipType];
- if(vipObject){
- UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, theBaseViewHeight, theBaseViewHeight)];
- bgView.backgroundColor = [UIColor clearColor];
- YYAnimatedImageView *medalImg = [[YYAnimatedImageView alloc] init];
- medalImg.frame = CGRectMake(0.0, 0.0, theBaseViewHeight, theBaseViewHeight);
- medalImg.contentMode = UIViewContentModeScaleAspectFit;
-
- NSString *urlStr = vipObject.thumbnail;
- NSURL *url = [NSURL URLWithString:urlStr];
- [medalImg setImageWithURL:url placeholder:nil];
- [bgView addSubview:medalImg];
-
- NSMutableAttributedString *vipImgAttri = [NSMutableAttributedString attachmentStringWithContent:bgView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(theBaseViewHeight, theBaseViewHeight) alignToFont:MOTextLabelFont alignment:YYTextVerticalAlignmentCenter];
- [vipImgAttri appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
- [contentStr insertAttributedString:[vipImgAttri copy] atIndex:0];
- }
- else{
- //旧版 VIP 静态图
- UIImage *vipImg = [MOTextTools getVipIconWith:vipType];
- NSTextAttachment *vipAttachment;
- if(vipImg){
- CGSize vipSize;
- vipAttachment = [[NSTextAttachment alloc] init];
- vipAttachment.image = vipImg;
- //字体行高
- UIFont *font = MOTextLabelFont;
- CGFloat attachmentHeight = font.lineHeight;
- CGFloat imgSizeHeight = GetParamNotZero(vipImg.size.height);
- CGFloat attachmentWidth = attachmentHeight * vipImg.size.width/ imgSizeHeight;
- vipAttachment.bounds = CGRectMake(0, (font.capHeight-font.lineHeight)/2, attachmentWidth, attachmentHeight);
- vipSize = CGSizeMake(attachmentWidth, attachmentHeight);
-
- NSMutableAttributedString *vipImgAttri = [NSMutableAttributedString attachmentStringWithContent:vipImg contentMode:UIViewContentModeScaleAspectFit attachmentSize:vipSize alignToFont:MOTextLabelFont alignment:YYTextVerticalAlignmentCenter];
- //生成NSAttributedString
- // NSMutableAttributedString *vipImgAttri = [[NSAttributedString attributedStringWithAttachment:vipAttachment] mutableCopy];
-
- [vipImgAttri appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
- [contentStr insertAttributedString:[vipImgAttri copy] atIndex:0];
- }
- }
- }
- return contentStr;
- }
- + (NSMutableAttributedString *)toAddLevelInfoWith:(NSMutableAttributedString *)contentStr And:(NSInteger)levelNum{
-
- NSArray *levelInfoArr = [MOSvgaSourceManage shareManager].allLevelSoureArr;
- MOStoreInfo *medalInfo;
- for (MOStoreInfo *object in levelInfoArr) {
- if(levelNum >= object.limit){
- medalInfo = object;
- break;
- }
- }
-
- if(medalInfo.res.length > 0){
-
- //这里调整的话, 请同时调整 MOBaseLevelView
- CGFloat levelWidth = MOLevelNormalWidth;
- CGFloat levelLabelX = 14.0;
- CGFloat levelLabexWidth = levelWidth - levelLabelX;
- if(levelNum >= 100){
- levelWidth = MOLevelMaxWidth;
- levelLabexWidth = levelWidth - levelLabelX - 5.0;
- }
- else if (levelNum < 10){
- levelWidth = MOLevelMixWidth;
- levelLabelX = 13.0;
- levelLabexWidth = levelWidth - levelLabelX;
- }
- UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, levelWidth, kRtmBaseViewHeight)];
- bgView.backgroundColor = [UIColor clearColor];
-
- YYAnimatedImageView *levelImg = [[YYAnimatedImageView alloc] init];
- levelImg.frame = CGRectMake(0.0, 0.0, levelWidth, 16.0);
- levelImg.contentMode = UIViewContentModeScaleAspectFit;
- NSURL *url = [NSURL URLWithString:medalInfo.res];
- [levelImg setImageWithURL:url placeholder:nil];
- [bgView addSubview:levelImg];
-
- UILabel *levelLabel = [[UILabel alloc] initWithFrame:CGRectMake(levelLabelX, 0, levelLabexWidth, kRtmBaseViewHeight)];
- levelLabel.font = [MOTextTools poppinsExtraBoldFont:10.0];
- levelLabel.textColor = [UIColor whiteColor];
- levelLabel.textAlignment = NSTextAlignmentCenter;
- levelLabel.text = [NSString stringWithFormat:@"%zd",levelNum];
- [bgView addSubview:levelLabel];
- CGSize viewSize = bgView.size;
-
- NSMutableAttributedString *levelImgAttri = [NSMutableAttributedString attachmentStringWithContent:bgView contentMode:UIViewContentModeScaleAspectFit attachmentSize:viewSize alignToFont:MOTextLabelFont alignment:YYTextVerticalAlignmentCenter];
- [levelImgAttri appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
- [contentStr insertAttributedString:[levelImgAttri copy] atIndex:0];
-
- return contentStr;
- }
- else{
- UIImage *levelImg = [MOTextTools createLevelImageViewWith:levelNum];
- CGSize levelSize;
- //创建一个NSTextAttachment
- NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
- attachment.image = levelImg;
- //字体行高
- UIFont *font = MOTextLabelFont;
- CGFloat attachmentHeight = font.lineHeight;
- CGFloat imgSizeHeight = GetParamNotZero(levelImg.size.height);
- CGFloat attachmentWidth = attachmentHeight * levelImg.size.width/ imgSizeHeight;
- attachment.bounds = CGRectMake(0, (font.capHeight-font.lineHeight)/2, attachmentWidth, attachmentHeight);
- levelSize = CGSizeMake(attachmentWidth, attachmentHeight);
-
- //生成NSAttributedString
- NSMutableAttributedString *levelImgAttri = [NSMutableAttributedString attachmentStringWithContent:levelImg contentMode:UIViewContentModeScaleAspectFit attachmentSize:levelSize alignToFont:MOTextLabelFont alignment:YYTextVerticalAlignmentCenter];
- // NSMutableAttributedString *levelImgAttri = [[NSAttributedString attributedStringWithAttachment:attachment] mutableCopy];
-
- [levelImgAttri appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
- [contentStr insertAttributedString:[levelImgAttri copy] atIndex:0];
-
- return contentStr;
- }
- }
- + (NSMutableAttributedString *)toAddSmallLevelInfoWith:(NSMutableAttributedString *)contentStr And:(NSInteger)levelNum AndHeight:(CGFloat)viewHeight AndAlignToFont:(UIFont *)theFont{
-
- NSArray *levelInfoArr = [MOSvgaSourceManage shareManager].allLevelSoureArr;
- MOStoreInfo *medalInfo;
- for (MOStoreInfo *object in levelInfoArr) {
- if(levelNum >= object.limit){
- medalInfo = object;
- break;
- }
- }
-
- CGFloat levelHeight = 14.0;
- if(viewHeight > 0){
- levelHeight = viewHeight;
- }
-
- if(medalInfo.res.length > 0){
-
- //这里调整的话, 请同时调整 MOBaseLevelView
- CGFloat levelWidth = MOLevelNormalWidth;
- CGFloat levelLabelX = 13.0;
- CGFloat levelLabexWidth = levelWidth - levelLabelX;
-
- if(levelNum >= 100){
- levelWidth = MOLevelMaxWidth;
- levelLabexWidth = levelWidth - levelLabelX - 5.0;
- }
- else if (levelNum < 10){
- levelWidth = MOLevelMixWidth;
- levelLabelX = 12.0;
- levelLabexWidth = levelWidth - levelLabelX;
- }
- UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, levelWidth, levelHeight)];
- bgView.backgroundColor = [UIColor clearColor];
-
- YYAnimatedImageView *levelImg = [[YYAnimatedImageView alloc] init];
- levelImg.frame = CGRectMake(0.0, 0.0, levelWidth, levelHeight);
- levelImg.contentMode = UIViewContentModeScaleAspectFit;
- NSURL *url = [NSURL URLWithString:medalInfo.res];
- [levelImg setImageWithURL:url placeholder:nil];
- [bgView addSubview:levelImg];
-
- UILabel *levelLabel = [[UILabel alloc] initWithFrame:CGRectMake(levelLabelX, 0, levelLabexWidth, levelHeight)];
- levelLabel.font = [MOTextTools poppinsExtraBoldFont:8.0];
- levelLabel.textColor = [UIColor whiteColor];
- levelLabel.textAlignment = NSTextAlignmentCenter;
- levelLabel.text = [NSString stringWithFormat:@"%zd",levelNum];
- [bgView addSubview:levelLabel];
- CGSize viewSize = bgView.size;
-
- NSMutableAttributedString *levelImgAttri = [NSMutableAttributedString attachmentStringWithContent:bgView contentMode:UIViewContentModeScaleAspectFit attachmentSize:viewSize alignToFont:theFont alignment:YYTextVerticalAlignmentCenter];
- [contentStr insertAttributedString:[levelImgAttri copy] atIndex:0];
-
- return contentStr;
- }
- else{
- UIImage *levelImg = [MOTextTools createLevelImageViewWith:levelNum];
- CGSize levelSize;
- //创建一个NSTextAttachment
- NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
- attachment.image = levelImg;
- //字体行高
- UIFont *font = theFont;
- CGFloat attachmentHeight = font.lineHeight;
- CGFloat imgSizeHeight = GetParamNotZero(levelImg.size.height);
- CGFloat attachmentWidth = attachmentHeight * levelImg.size.width/ imgSizeHeight;
- attachment.bounds = CGRectMake(0, (font.capHeight-font.lineHeight)/2, attachmentWidth, attachmentHeight);
- levelSize = CGSizeMake(attachmentWidth, attachmentHeight);
-
- //生成NSAttributedString
- NSMutableAttributedString *levelImgAttri = [NSMutableAttributedString attachmentStringWithContent:levelImg contentMode:UIViewContentModeScaleAspectFit attachmentSize:levelSize alignToFont:theFont alignment:YYTextVerticalAlignmentCenter];
- // NSMutableAttributedString *levelImgAttri = [[NSAttributedString attributedStringWithAttachment:attachment] mutableCopy];
- [contentStr insertAttributedString:[levelImgAttri copy] atIndex:0];
-
- return contentStr;
- }
- }
- //增加勋章
- + (NSMutableAttributedString *)toAddMedalInfoWith:(NSMutableAttributedString *)contentStr And:(NSArray *)medalList{
-
- if(medalList.count > 0){
-
- NSMutableAttributedString *medalBaseStr = [[NSMutableAttributedString alloc] init];
- BOOL isHave = NO;
- for (NSNumber *number in medalList) {
- NSInteger value = [number integerValue];
- MOStoreInfo *medalInfo = [[MOSvgaSourceManage shareManager] getMedalInfoWithCode:value];
- if(medalInfo){
- isHave = YES;
- UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 17.0, 17.0)];
- bgView.backgroundColor = [UIColor clearColor];
- YYAnimatedImageView *medalImg = [[YYAnimatedImageView alloc] init];
- medalImg.frame = CGRectMake(0.0, 0.0, 17.0, 17.0);
- medalImg.contentMode = UIViewContentModeScaleAspectFit;
-
- NSString *urlStr = medalInfo.thumbnail;
- if(urlStr.length == 0){
- urlStr = medalInfo.icon;
- }
-
- NSURL *url = [NSURL URLWithString:urlStr];
- [medalImg setImageWithURL:url placeholder:nil];
- [bgView addSubview:medalImg];
-
- NSMutableAttributedString *medalImgAttri = [NSMutableAttributedString attachmentStringWithContent:bgView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(17.0, 17.0) alignToFont:MOTextLabelFont alignment:YYTextVerticalAlignmentCenter];
- [medalImgAttri appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
- [medalBaseStr appendAttributedString:[medalImgAttri copy]];
-
- }
- }
-
- if(isHave){
- [contentStr insertAttributedString:[medalBaseStr copy] atIndex:0];
- }
-
- return contentStr;
-
- }
- else{
- return contentStr;
- }
- }
- //增加勋章
- + (NSMutableAttributedString *)toCreateMedalInfoWithMedalListAnd:(NSArray *)medalList AndMedalWidth:(CGFloat)medalWidth AndUserBigImage:(BOOL)userBig AndSpaingStr:(NSString *)spacingStr{
-
- NSMutableAttributedString *medalBaseStr = [[NSMutableAttributedString alloc] initWithString:@""];
- if(medalList.count > 0){
- BOOL isHave = NO;
- for (NSNumber *number in medalList) {
- NSInteger value = [number integerValue];
- MOStoreInfo *medalInfo = [[MOSvgaSourceManage shareManager] getMedalInfoWithCode:value];
- if(medalInfo){
- isHave = YES;
- UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, medalWidth, medalWidth)];
- bgView.backgroundColor = [UIColor clearColor];
- YYAnimatedImageView *medalImg = [[YYAnimatedImageView alloc] init];
- medalImg.frame = CGRectMake(0.0, 0.0, medalWidth, medalWidth);
- medalImg.contentMode = UIViewContentModeScaleAspectFit;
-
- NSString *urlStr;
- if(userBig){
- urlStr = medalInfo.icon;
- if(urlStr.length == 0){
- urlStr = medalInfo.image;
- }
- }
- else{
- urlStr = medalInfo.thumbnail;
- if(urlStr.length == 0){
- urlStr = medalInfo.icon;
- }
- }
-
- NSURL *url = [NSURL URLWithString:urlStr];
- [medalImg setImageWithURL:url placeholder:nil];
- [bgView addSubview:medalImg];
-
- NSMutableAttributedString *medalImgAttri = [NSMutableAttributedString attachmentStringWithContent:bgView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(medalWidth, medalWidth) alignToFont:MOTextLabelFont alignment:YYTextVerticalAlignmentCenter];
- [medalImgAttri appendAttributedString:[[NSAttributedString alloc] initWithString:spacingStr]];
- [medalBaseStr appendAttributedString:[medalImgAttri copy]];
-
- }
- }
- }
-
- return medalBaseStr;
- }
- + (NSMutableAttributedString *)toAddFanClubInfoWith:(NSMutableAttributedString *)contentStr And:(MORtmFanBean *)fanData{
-
- if(fanData.name.length > 0){
- MOFanClubNameplateView *fanView = [[MOFanClubNameplateView alloc] init];
- fanView.grade = fanData.level;
- fanView.titleLab.text = fanData.name;
- CGFloat gradeWidth = [fanView getNameplateWidth];
- fanView.frame = CGRectMake(0.0, 0.0, gradeWidth, 15.0);
- CGSize fanViewSize = CGSizeMake(gradeWidth, 15.0);
-
- NSMutableAttributedString *fanAttri = [NSMutableAttributedString attachmentStringWithContent:fanView contentMode:UIViewContentModeScaleAspectFit attachmentSize:fanViewSize alignToFont:MOTextLabelFont alignment:YYTextVerticalAlignmentCenter];
- [fanAttri appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
- [contentStr insertAttributedString:[fanAttri copy] atIndex:0];
-
- return contentStr;
- }
- else{
- return contentStr;
- }
- }
- + (NSMutableAttributedString *)base_colorfulStringWith:(NSString *)contentStr AndNameStr:(NSString *)nameStr {
-
- // 创建属性字符串,整体颜色为白色
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:contentStr attributes:@{NSForegroundColorAttributeName:[MOTools colorWithHexString:@"#FFFFFF" alpha:1.0]}];
-
- if(nameStr.length != 0){
- NSRange redRange = [contentStr rangeOfString:nameStr];
- if(redRange.location != NSNotFound){
- // 将最后三个字符的颜色设置为红色
- [attributedString addAttribute:NSForegroundColorAttributeName value:kBaseTextHightlightColor_1 range:redRange];
- }
- }
-
- return attributedString;
- }
- + (NSMutableAttributedString *)base_colorfulStringWith:(NSString *)contentStr AndNameStr:(NSString *)nameStr AndBaseColor:(NSString *)baseColorStr AndNameColor:(NSString *)nameColorStr {
-
- // 创建属性字符串,整体颜色为白色
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:contentStr attributes:@{NSForegroundColorAttributeName:[MOTools colorWithHexString:baseColorStr alpha:1.0]}];
-
- if(nameStr.length != 0){
- NSRange redRange = [contentStr rangeOfString:nameStr];
- if(redRange.location != NSNotFound){
- // 将最后三个字符的颜色设置为红色
- [attributedString addAttribute:NSForegroundColorAttributeName value:[MOTools colorWithHexString:nameColorStr alpha:1.0] range:redRange];
- }
- }
- return attributedString;
- }
- + (NSMutableAttributedString *)base_colorObjectStringWith:(NSString *)contentStr AndNameStr:(NSString *)nameStr AndBaseColor:(UIColor *)baseColor AndNameColor:(UIColor *)nameColor{
- // 创建属性字符串,整体颜色为白色
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:contentStr attributes:@{NSForegroundColorAttributeName:baseColor}];
-
- if(nameStr.length != 0){
- NSRange redRange = [contentStr rangeOfString:nameStr];
- if(redRange.location != NSNotFound){
- // 将最后三个字符的颜色设置为红色
- [attributedString addAttribute:NSForegroundColorAttributeName value:nameColor range:redRange];
- }
- }
- return attributedString;
- }
- + (NSMutableAttributedString *)base_colorfulStringWith:(NSString *)contentStr AndNameStr:(NSString *)nameStr AndBaseColor:(NSString *)baseColorStr AndNameColor:(NSString *)nameColorStr AndStrokeColor:(NSString *)strokeColorStr AndStrokeWidth:(NSInteger)strokeWidth AndShadowColor:(NSString *)shadowColorStr{
-
- NSDictionary *attributes = @{
- NSForegroundColorAttributeName: [MOTools colorWithHexString:baseColorStr alpha:1.0],
- NSStrokeWidthAttributeName: @(strokeWidth), // 描边宽度,正数表示描边宽度,负数表示填充宽度
- NSStrokeColorAttributeName: [MOTools colorWithHexString:strokeColorStr alpha:1.0], // 描边颜色
- NSShadowAttributeName: ({
- NSShadow *shadow = [NSShadow new];
- shadow.shadowColor = [MOTools colorWithHexString:shadowColorStr alpha:1.0]; // 阴影颜色
- shadow.shadowOffset = CGSizeMake(1.0, 1.0); // 阴影偏移量
- shadow.shadowBlurRadius = 2.0; // 阴影模糊半径
- shadow;
- })
- };
-
- // 创建属性字符串,整体颜色为白色
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:contentStr attributes:attributes];
-
- if(nameStr.length != 0){
- NSRange redRange = [contentStr rangeOfString:nameStr];
- if(redRange.location != NSNotFound){
- // 将最后三个字符的颜色设置为红色
- [attributedString addAttribute:NSForegroundColorAttributeName value:[MOTools colorWithHexString:nameColorStr alpha:1.0] range:redRange];
- }
- }
- return attributedString;
- }
- ///变更字体中的颜色 - 按照最后查找原则
- + (NSMutableAttributedString *)base_backwardsSearchColorfulStringWith:(NSString *)contentStr AndNameStr:(NSString *)nameStr AndBaseColor:(NSString *)baseColorStr AndNameColor:(NSString *)nameColorStr{
- // 创建属性字符串,整体颜色为白色
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:contentStr attributes:@{NSForegroundColorAttributeName:[MOTools colorWithHexString:baseColorStr alpha:1.0]}];
-
- if(nameStr.length != 0){
- NSRange redRange = [contentStr rangeOfString:nameStr options:NSBackwardsSearch];
- if(redRange.location != NSNotFound){
- // 将最后三个字符的颜色设置为红色
- [attributedString addAttribute:NSForegroundColorAttributeName value:[MOTools colorWithHexString:nameColorStr alpha:1.0] range:redRange];
- }
- }
- return attributedString;
- }
- + (NSMutableAttributedString *)add_atColorfulStringWith:(NSMutableAttributedString *)contentStr AndAtString:(NSString *)atNickname{
-
- NSString *baseStr = [contentStr string];
- NSString *theAtName = atNickname;
-
- if(atNickname.length != 0){
- if([atNickname containsString:@","]){
- theAtName = [atNickname componentsSeparatedByString:@","].firstObject;
- }
- }
-
- NSRange redRange = [baseStr rangeOfString:[NSString stringWithFormat:@"@%@",theAtName]];
- if(redRange.location != NSNotFound){
- // 将最后三个字符的颜色设置为红色
- [contentStr addAttribute:NSForegroundColorAttributeName value:kBaseTextHightlightColor_1 range:redRange];
- }
-
- return contentStr;
- }
- + (NSMutableAttributedString *)tipAllBlueStringWith:(NSString *)contentStr{
- // 创建属性字符串,整体颜色为白色
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:contentStr attributes:@{NSForegroundColorAttributeName:kBaseTextHightlightColor_1,NSFontAttributeName:MOTextLabelFont}];
- return attributedString;
- }
- + (NSMutableAttributedString *)tipAllWhiteStringWith:(NSString *)contentStr{
- // 创建属性字符串,整体颜色为白色
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:contentStr attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:MOTextLabelFont}];
- return attributedString;
- }
- + (NSMutableAttributedString *)colorfulStringWith:(NSString *)contentStr AndNameStr:(NSString *)nameStr {
-
- // 创建属性字符串,整体颜色为白色
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:contentStr attributes:@{NSForegroundColorAttributeName:[MOTools colorWithHexString:@"#EFE85C" alpha:1.0]}];
-
- NSRange redRange = [contentStr rangeOfString:nameStr];
- if(redRange.location != NSNotFound){
- // 将最后三个字符的颜色设置为红色
- [attributedString addAttribute:NSForegroundColorAttributeName value:kBaseTextHightlightColor_1 range:redRange];
- }
-
- return attributedString;
- }
- + (UIImage *)createLevelImageViewWith:(NSInteger)gradeNum {
-
- CGFloat iconWidth = 0.0;
- CGFloat labLeft = 12.0;
-
- UIImage *iconImg = [MOTextTools getLevelIconImgWith:gradeNum];
- if(iconImg){
- iconWidth = 13.0;
- labLeft = 15.0 + 5.0;
- }
-
- NSString *textStr = [NSString stringWithFormat:@"%zd",gradeNum];
- UIFont *textFont = MOLevelLabelFont;
- CGFloat textWidth = [MOTools getWidthWithString:textStr font:textFont];
- CGFloat viewWidth = textWidth + 10.0 + iconWidth + 5.0;
-
- UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, viewWidth, kRtmBaseViewHeight)];
- bgView.backgroundColor = [UIColor clearColor];
-
- UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, viewWidth, kRtmBaseViewHeight)];
- view.backgroundColor = [MOTextTools getLevelColorWith:gradeNum];
-
- if(iconImg){
- UIImageView *iconImgView = [[UIImageView alloc] initWithImage:iconImg];
- iconImgView.frame = CGRectMake(5.0, 2.0, iconWidth, iconWidth);
- iconImgView.contentMode = UIViewContentModeScaleAspectFit;
- [view addSubview:iconImgView];
- }
-
- UILabel *numLab = [[UILabel alloc] initWithFrame:CGRectMake(labLeft, 1.5, textWidth, 14.0)];
- numLab.text = textStr;
- numLab.textColor = [UIColor whiteColor];
- numLab.font = textFont;
- [view addSubview:numLab];
- view.layer.cornerRadius = 17.0 / 2.0;
- view.layer.masksToBounds = YES;
-
- [bgView addSubview:view];
-
- UIImage *resultImg = [MOTextTools snapshotWithView:bgView];
- return resultImg;
-
- }
- + (UIColor *)getLevelColorWith:(NSInteger)gradeNum {
-
- UIColor *needColor;
-
- if(gradeNum >= 135){
- needColor = [MOTools colorWithHexString:@"#FF7B1B" alpha:1.0];
- return needColor;
- }
-
- if(gradeNum >= 120){
- needColor = [MOTools colorWithHexString:@"#F16582" alpha:1.0];
- return needColor;
- }
-
- if(gradeNum >= 100){
- needColor = [MOTools colorWithHexString:@"#D58AEF" alpha:1.0];
- return needColor;
- }
-
- if(gradeNum >= 80){
- needColor = [MOTools colorWithHexString:@"#FB9DC1" alpha:1.0];
- return needColor;
- }
-
- if(gradeNum >= 65){
- needColor = [MOTools colorWithHexString:@"#F051E0" alpha:1.0];
- return needColor;
- }
-
- if(gradeNum >= 50){
- needColor = [MOTools colorWithHexString:@"#B165FD" alpha:1.0];
- return needColor;
- }
-
- if(gradeNum >= 30){
- needColor = [MOTools colorWithHexString:@"#728EF2" alpha:1.0];
- return needColor;
- }
-
- if(gradeNum >= 15){
- needColor = [MOTools colorWithHexString:@"#55BBDE" alpha:1.0];
- return needColor;
- }
- else{
- needColor = [MOTools colorWithHexString:@"#44CCA7" alpha:1.0];
- return needColor;
- }
- }
- + (nullable UIImage *)getVipIconWith:(NSInteger)vipType{
- if(vipType == 0){
- return nil;
- }
-
- UIImage *vipImg;
-
- if(vipType == 1){
- vipImg = [UIImage imageNamed:@"v_2_vip_4_282"];
- vipImg = [vipImg imageByResizeToSize:CGSizeMake(vipImg.size.width / 2.0, vipImg.size.height / 2.0) contentMode:UIViewContentModeScaleAspectFit];
- return vipImg;
- }
-
- if(vipType == 2){
- vipImg = [UIImage imageNamed:@"v_2_vip_3_282"];
- vipImg = [vipImg imageByResizeToSize:CGSizeMake(vipImg.size.width / 2.0, vipImg.size.height / 2.0) contentMode:UIViewContentModeScaleAspectFit];
- return vipImg;
- }
-
- if(vipType == 5){
- vipImg = [UIImage imageNamed:@"v_2_vip_5_282"];
- vipImg = [vipImg imageByResizeToSize:CGSizeMake(vipImg.size.width / 2.0, vipImg.size.height / 2.0) contentMode:UIViewContentModeScaleAspectFit];
- return vipImg;
- }
-
- if(vipType == 6){
- vipImg = [UIImage imageNamed:@"v_2_vip_6_282"];
- vipImg = [vipImg imageByResizeToSize:CGSizeMake(vipImg.size.width / 2.0, vipImg.size.height / 2.0) contentMode:UIViewContentModeScaleAspectFit];
- return vipImg;
- }
-
- if(vipType == 3){
- vipImg = [UIImage imageNamed:@"v_2_vip_2_282"];
- vipImg = [vipImg imageByResizeToSize:CGSizeMake(vipImg.size.width / 2.0, vipImg.size.height / 2.0) contentMode:UIViewContentModeScaleAspectFit];
- return vipImg;
- }
- else{
- vipImg = [UIImage imageNamed:@"v_2_vip_1_282"];
- vipImg = [vipImg imageByResizeToSize:CGSizeMake(vipImg.size.width / 2.0, vipImg.size.height / 2.0) contentMode:UIViewContentModeScaleAspectFit];
- return vipImg;
- }
- }
- + (UIImage *)getLevelIconImgWith:(NSInteger)gradeNum{
-
- UIImage *needImg;
-
- if(gradeNum >= 135){
- needImg = [UIImage imageNamed:@"icon_level_135"];
- return needImg;
- }
-
- if(gradeNum >= 120){
- needImg = [UIImage imageNamed:@"icon_level_120"];
- return needImg;
- }
-
- if(gradeNum >= 100){
- needImg = [UIImage imageNamed:@"icon_level_100"];
- return needImg;
- }
-
- if(gradeNum >= 80){
- needImg = [UIImage imageNamed:@"icon_level_80"];
- return needImg;
- }
-
- if(gradeNum >= 65){
- needImg = [UIImage imageNamed:@"icon_level_65"];
- return needImg;
- }
-
- if(gradeNum >= 50){
- needImg = [UIImage imageNamed:@"icon_level_50"];
- return needImg;
- }
-
- if(gradeNum >= 30){
- needImg = [UIImage imageNamed:@"icon_level_30"];
- return needImg;
- }
-
- if(gradeNum >= 15){
- needImg = [UIImage imageNamed:@"icon_level_15"];
- return needImg;
- }
- else{
- needImg = [UIImage imageNamed:@"icon_level_1"];
- return needImg;
- }
- }
- + (UIImage *)getBubbleImgWithCodeNum:(NSInteger)code{
- UIImage *bubbleImg;
-
- switch (code) {
- case 1096:
- {
- bubbleImg = [UIImage imageNamed:@"icon_bubble_weekly_star"];
- }
- break;
- case 1083:
- {
- bubbleImg = [UIImage imageNamed:@"icon_bubble_taohua"];
- }
- break;
- case 1082:
- {
- bubbleImg = [UIImage imageNamed:@"icon_bubble_dasao"];
- }
- break;
- case 1081:
- {
- bubbleImg = [UIImage imageNamed:@"icon_bubble_aixin"];
- }
- break;
- case 1080:
- {
- bubbleImg = [UIImage imageNamed:@"icon_bubble_hai"];
- }
- break;
- case 1079:
- {
- bubbleImg = [UIImage imageNamed:@"icon_bubble_zuqiu"];
- }
- break;
- case 1078:
- {
- bubbleImg = [UIImage imageNamed:@"icon_bubble_jingyu"];
- }
- break;
- case 1077:
- {
- bubbleImg = [UIImage imageNamed:@"icon_bubble_youle"];
- }
- break;
- case 1071:
- {
- //家族3
- bubbleImg = [UIImage imageNamed:@"icon_family_no_3"];
- }
- break;
- case 1070:
- {
- //家族2
- bubbleImg = [UIImage imageNamed:@"icon_family_no_2"];
- }
- break;
- case 1069:
- {
- //家族1
- bubbleImg = [UIImage imageNamed:@"icon_family_no_1"];
- }
- break;
- case 1055:
- case 1244:
- {
- //VIP - k
- bubbleImg = [UIImage imageNamed:@"icon_bubble_vip_k"];
- }
- break;
- case 1054:
- case 1245:
- {
- //VIP - b
- bubbleImg = [UIImage imageNamed:@"icon_bubble_vip_b"];
- }
- break;
- case 1053:
- case 1246:
- {
- //VIP - v
- bubbleImg = [UIImage imageNamed:@"icon_bubble_vip_v"];
- }
- break;
- case 1052:
- case 1247:
- {
- //VIP - m
- bubbleImg = [UIImage imageNamed:@"icon_bubble_vip_m"];
- }
- break;
- case 1248:
- {
- //VIP - m
- bubbleImg = [UIImage imageNamed:@"icon_bubble_vip_5"];
- }
- break;
- case 1249:
- {
- //VIP - m
- bubbleImg = [UIImage imageNamed:@"icon_bubble_vip_6"];
- }
- break;
- case 1202:
- {
- //VIP - m
- bubbleImg = [UIImage imageNamed:@"v_2_new_b_4"];
- }
- break;
- case 1241:
- {
- //VIP - m
- bubbleImg = [UIImage imageNamed:@"v_2_new_b_2"];
- }
- break;
- case 1242:
- {
- //VIP - m
- bubbleImg = [UIImage imageNamed:@"v_2_new_b_3"];
- }
- break;
- case 1243:
- {
- //VIP - m
- bubbleImg = [UIImage imageNamed:@"v_2_new_b_5"];
- }
- break;
- case 1183:
- {
- bubbleImg = [UIImage imageNamed:@"icon_bubble_t_1"];
- }
- break;
- case 1182:
- {
- bubbleImg = [UIImage imageNamed:@"icon_bubble_t_2"];
- }
- break;
- case 1181:
- {
- bubbleImg = [UIImage imageNamed:@"icon_bubble_t_3"];
- }
- break;
- case 1180:
- {
- bubbleImg = [UIImage imageNamed:@"icon_bubble_t_4"];
- }
- break;
- case 1178:
- {
- bubbleImg = [UIImage imageNamed:@"icon_bubble_t_5"];
- }
- break;
- case 1176:
- {
- bubbleImg = [UIImage imageNamed:@"icon_bubble_t_6"];
- }
- break;
- case 1170:
- {
- bubbleImg = [UIImage imageNamed:@"icon_bubble_t_7"];
- }
- break;
- case 1169:
- {
- bubbleImg = [UIImage imageNamed:@"icon_bubble_t_8"];
- }
- break;
-
- default:
- bubbleImg = nil;
-
- break;
- }
-
- return bubbleImg;
- }
- + (CGSize)textMessageCellSizeWith:(MORtmEntity *)rtmEntity
- {
-
- NSMutableAttributedString *attributedString = [MOTextTools creteTextWith:rtmEntity];
-
- [attributedString addAttributes:MOTextLabelAttributesDict range:NSMakeRange(0, attributedString.string.length)];
-
- YYTextContainer *container = [YYTextContainer new];
- container.size = CGSizeMake(MOTextLabelMaxWidth, CGFLOAT_MAX); // 宽度固定,高度无限制
- container.linePositionModifier = nil; // 可自定义行样式
- container.insets = UIEdgeInsetsMake(MOContentBaseTopSpcing, MOContentBaseLeftSpacing, MOContentBaseBottomSpcing, MOContentBaseRightSpacing);
-
- // 创建文本布局
- YYTextLayout *layout = [YYTextLayout layoutWithContainer:container text:attributedString];
- // 获取文本高度
- CGSize textSize = layout.textBoundingSize;
-
- MORtmJosnEntity *jsonEntity = (MORtmJosnEntity *)rtmEntity.data;
- if(rtmEntity.type == MORtmChat){
- // 如果是聊天消息,增加顶部间距
- textSize.height += MOTextTitleLabeHeight;
- }
-
- if(rtmEntity.type == SystemOrder && (jsonEntity.type == 9 || jsonEntity.type == 10)){
- //红包
- textSize.height += MOTextRedEnvelopeViewHeight;
- }
-
- return textSize;
- }
- + (CGSize)textMessageCellSizeWithString:(NSString *)contentStr
- {
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:contentStr];
-
- [attributedString addAttributes:MOTextLabelAttributesDict range:NSMakeRange(0, attributedString.string.length)];
-
- CGSize size = [attributedString boundingRectWithSize:CGSizeMake(MOTextLabelMaxWidth, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin context:nil].size;
- return size;
- }
- + (CGFloat)getWidthWith:(MORtmEntity *)rtmEntity
- {
- NSMutableAttributedString *attributedString = [MOTextTools creteTextWith:rtmEntity];
- [attributedString addAttributes:MOTextLabelAttributesDict range:NSMakeRange(0, attributedString.string.length)];
-
- YYTextContainer *container = [YYTextContainer new];
- container.size = CGSizeMake(MAXFLOAT, MAXFLOAT); // 宽度无限制,高度无限制
- container.linePositionModifier = nil; // 可自定义行样式
- container.insets = UIEdgeInsetsMake(MOContentBaseTopSpcing, MOContentBaseLeftSpacing, MOContentBaseBottomSpcing, MOContentBaseRightSpacing);
-
- // 创建文本布局
- YYTextLayout *layout = [YYTextLayout layoutWithContainer:container text:attributedString];
- // 获取文本高度
- CGSize textSize = layout.textBoundingSize;
- CGFloat textWidth = textSize.width + 1.0;
-
- return textWidth;
- }
- + (CGFloat)getTheAttributedTextWidthWith:(NSAttributedString *)contentStr{
- CGFloat width = [contentStr boundingRectWithSize:CGSizeZero options:NSStringDrawingUsesLineFragmentOrigin context:nil].size.width + 1.0;
- return width;
- }
- + (UIImage *)snapshotWithView:(UIView *)view {
- UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, [UIScreen mainScreen].scale);
- [view.layer renderInContext:UIGraphicsGetCurrentContext()];
- UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- return image;
- }
- + (NSMutableParagraphStyle *)textLabelParagraphStyle
- {
- NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
- paragraphStyle.lineSpacing = MOTextLabelLineSpacing;
- return paragraphStyle;
- }
- + (UIImage *)getFanLevelImgWith:(NSInteger)gradeNum{
- UIImage *needImg;
-
- if(gradeNum >= 60){
- needImg = [UIImage imageNamed:@"icon_fan_club_lv_60"];
- return needImg;
- }
-
- if(gradeNum >= 50){
- needImg = [UIImage imageNamed:@"icon_fan_club_lv_50"];
- return needImg;
- }
-
- if(gradeNum >= 40){
- needImg = [UIImage imageNamed:@"icon_fan_club_lv_40"];
- return needImg;
- }
-
- if(gradeNum >= 30){
- needImg = [UIImage imageNamed:@"icon_fan_club_lv_30"];
- return needImg;
- }
-
- if(gradeNum >= 20){
- needImg = [UIImage imageNamed:@"icon_fan_club_lv_20"];
- return needImg;
- }
-
- if(gradeNum >= 11){
- needImg = [UIImage imageNamed:@"icon_fan_club_lv_11"];
- return needImg;
- }
-
- if(gradeNum >= 6){
- needImg = [UIImage imageNamed:@"icon_fan_club_lv_6"];
- return needImg;
- }
-
- needImg = [UIImage imageNamed:@"icon_fan_club_lv_1"];
- return needImg;
- }
- + (UIImage *)getFanLiveImgWith:(NSInteger)gradeNum{
- UIImage *needImg;
-
- if(gradeNum >= 60){
- needImg = [UIImage imageNamed:@"icon_fan_club_lv_s_60"];
- return needImg;
- }
-
- if(gradeNum >= 50){
- needImg = [UIImage imageNamed:@"icon_fan_club_lv_s_50"];
- return needImg;
- }
-
- if(gradeNum >= 40){
- needImg = [UIImage imageNamed:@"icon_fan_club_lv_s_40"];
- return needImg;
- }
-
- if(gradeNum >= 30){
- needImg = [UIImage imageNamed:@"icon_fan_club_lv_s_30"];
- return needImg;
- }
-
- if(gradeNum >= 20){
- needImg = [UIImage imageNamed:@"icon_fan_club_lv_s_20"];
- return needImg;
- }
-
- if(gradeNum >= 11){
- needImg = [UIImage imageNamed:@"icon_fan_club_lv_s_11"];
- return needImg;
- }
-
- if(gradeNum >= 6){
- needImg = [UIImage imageNamed:@"icon_fan_club_lv_s_6"];
- return needImg;
- }
-
- needImg = [UIImage imageNamed:@"icon_fan_club_lv_s_1"];
- return needImg;
- }
- + (UIImage *)getTheFanClubMedalWith:(NSInteger)level{
- UIImage *needImg;
-
- if(level >= 60){
- needImg = [UIImage imageNamed:@"icon_uesr_fan_60"];
- return needImg;
- }
-
- if(level >= 50){
- needImg = [UIImage imageNamed:@"icon_uesr_fan_50"];
- return needImg;
- }
-
- if(level >= 40){
- needImg = [UIImage imageNamed:@"icon_uesr_fan_40"];
- return needImg;
- }
-
- needImg = [UIImage imageNamed:@"icon_uesr_fan_30"];
- return needImg;
- }
- + (UIColor *)getFanLevelColorWith:(NSInteger)gradeNum {
-
- UIColor *needColor;
-
- if(gradeNum >= 60){
- needColor = [MOTools colorWithHexString:@"#F26868" alpha:1.0];
- return needColor;
- }
-
- if(gradeNum >= 50){
- needColor = [MOTools colorWithHexString:@"#FF7EA0" alpha:1.0];
- return needColor;
- }
-
- if(gradeNum >= 40){
- needColor = [MOTools colorWithHexString:@"#FC5DBB" alpha:1.0];
- return needColor;
- }
-
- if(gradeNum >= 30){
- needColor = [MOTools colorWithHexString:@"#C964F7" alpha:1.0];
- return needColor;
- }
-
- if(gradeNum >= 20){
- needColor = [MOTools colorWithHexString:@"#FC8B71" alpha:1.0];
- return needColor;
- }
-
- if(gradeNum >= 11){
- needColor = [MOTools colorWithHexString:@"#F5A768" alpha:1.0];
- return needColor;
- }
-
- if(gradeNum >= 6){
- needColor = [MOTools colorWithHexString:@"#F8C368" alpha:1.0];
- return needColor;
- }
-
- needColor = [MOTools colorWithHexString:@"#FBD562" alpha:1.0];
- return needColor;
- }
- //单位换算
- + (NSString *)numberToStringWith:(double)num{
- NSString *resultStr = @"";
- if(num < 1000){
- resultStr = [NSString stringWithFormat:@"%.f",num];
- }
- else if (num >= 1000 && num <= 999999){
- double newNum = num / 1000.0;
- resultStr = [NSString stringWithFormat:@"%.1fK",(floorf(newNum * 10) / 10)];
- }
- else if (num >= 1000000 && num <= 999999999){
- double newNum = num / 1000000.0;
- resultStr = [NSString stringWithFormat:@"%.1fM",(floorf(newNum * 10) / 10)];
- }
- else{
- double newNum = num / 1000000000.0;
- resultStr = [NSString stringWithFormat:@"%.1fB",(floorf(newNum * 10) / 10)];
- }
-
- return resultStr;
- }
- + (NSString *)numberToStringAboutTwoWith:(double)num{
- NSString *resultStr = @"";
- if (num < 10000) {
- resultStr = [NSString stringWithFormat:@"%.2f", num];
- }
- else if (num >= 10000 && num <= 999999) {
- double newNum = num / 1000.0;
- resultStr = [NSString stringWithFormat:@"%.2fK", newNum];
- }
- else if (num >= 1000000 && num <= 999999999) {
- double newNum = num / 1000000.0;
- resultStr = [NSString stringWithFormat:@"%.2fM", newNum];
- }
- else {
- double newNum = num / 1000000000.0;
- resultStr = [NSString stringWithFormat:@"%.2fB", newNum];
- }
- return resultStr;
- }
- + (NSString *)numberToStringNoPointWith:(double)num{
- NSString *resultStr = @"";
- if(num < 1000){
- resultStr = [NSString stringWithFormat:@"%.f",num];
- }
- else if (num >= 1000 && num <= 999999){
- double newNum = num / 1000.0;
- resultStr = [NSString stringWithFormat:@"%.fK",(floorf(newNum * 10) / 10)];
- }
- else if (num >= 1000000 && num <= 999999999){
- double newNum = num / 1000000.0;
- resultStr = [NSString stringWithFormat:@"%.fM",(floorf(newNum * 10) / 10)];
- }
- else{
- double newNum = num / 1000000000.0;
- resultStr = [NSString stringWithFormat:@"%.fB",(floorf(newNum * 10) / 10)];
- }
-
- return resultStr;
- }
- + (NSString *)minuteStrWith:(double)minute{
- NSString *resultStr = @"";
- if(minute < 60){
- resultStr = [NSString stringWithFormat:@"%.fMin",minute];
- }
- else{
- CGFloat hourNum = minute / 60;
- resultStr = [NSString stringWithFormat:@"%.fH",hourNum];
- }
- return resultStr;
- }
- + (NSString *)formatNumberDecimalValue:(double)value {
- NSString * string = [NSNumberFormatter localizedStringFromNumber:[NSNumber numberWithLongLong:value]
- numberStyle:NSNumberFormatterDecimalStyle];
- return string;
- }
- /// 小数转成百分比,去除小数部分
- + (NSString *)formatPercentage:(double)value {
- NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
- formatter.numberStyle = NSNumberFormatterPercentStyle;
- formatter.maximumFractionDigits = 1; // Set to 1 decimal place
- formatter.minimumFractionDigits = 0; // Avoid trailing zeros
- return [formatter stringFromNumber:@(value)];
- }
- /// SF-Pro-Display-HeavyItalic 斜体加粗
- /// @param fontSize 字号
- /// @param bold 加粗
- /// @param italic 斜体
- /// @param weight 加粗量级
- + (UIFont *)MODisplayFontWithSize:(CGFloat)fontSize
- bold:(BOOL)bold itatic:(BOOL)italic weight:(UIFontWeight)weight {
- UIFont *font = [UIFont systemFontOfSize:fontSize weight:weight];
- UIFontDescriptorSymbolicTraits symbolicTraits = 0;
- if (italic) {
- symbolicTraits |= UIFontDescriptorTraitItalic;
- }
- if (bold) {
- symbolicTraits |= UIFontDescriptorTraitBold;
- }
- UIFont *specialFont = [UIFont fontWithDescriptor:[[font fontDescriptor] fontDescriptorWithSymbolicTraits:symbolicTraits] size:font.pointSize];
- return specialFont;
- }
- + (UIFont *)getTheFontWithSize:(CGFloat)fontSize AndFontName:(NSString *)fontName{
- UIFont *customFont = [UIFont fontWithName:fontName size:fontSize];
- if(!customFont){
- customFont = [MOTextTools MODisplayFontWithSize:fontSize bold:YES itatic:NO weight:UIFontWeightMedium];
- }
- return customFont;
- }
- + (UIImage *)getTheDiamondImageWith:(NSInteger)diamond{
- UIImage *needImg;
-
- if(diamond >= 100000){
- needImg = [UIImage imageNamed:@"icon_diamond_4"];
- return needImg;
- }
-
- if(diamond >= 50000){
- needImg = [UIImage imageNamed:@"icon_diamond_3"];
- return needImg;
- }
-
- if(diamond >= 20000){
- needImg = [UIImage imageNamed:@"icon_diamond_2"];
- return needImg;
- }
-
- needImg = [UIImage imageNamed:@"icon_diamond_1"];
- return needImg;
- }
- /// 根据选中人 以及 麦位上的数据 生成一个礼物飘屏提示字符串
- + (NSString *)toGetTheGiftTipTextWith:(NSArray *)linkMics And:(MOUserProfile *)anchor And:(NSArray *)sendUserIdArr{
- NSString *resultStr = @"send you a gift";
- NSMutableArray *tempArr = [NSMutableArray array];
- BOOL isAll = YES;
-
- if([sendUserIdArr containsObject:anchor.id]){
- [tempArr addObject:anchor.nickname];
- }
- else{
- isAll = NO;
- }
-
- for (MOLinkMic *linkMic in linkMics) {
- if(linkMic.profile.id.length > 0){
- if([sendUserIdArr containsObject:linkMic.profile.id]){
- if(linkMic.profile.nickname){
- [tempArr addObject:linkMic.profile.nickname];
- }
- }
- else{
- isAll = NO;
- }
- }
- else{
- isAll = NO;
- }
- }
-
- if(tempArr.count > 0){
- if(isAll){
- resultStr = @"send to all";
- }
- else{
- resultStr = [tempArr componentsJoinedByString:@","];
- resultStr = [NSString stringWithFormat:@"send to %@",resultStr];
- }
- }
-
- return resultStr;
- }
- + (NSMutableAttributedString *)addDeleteLineWith:(NSString *)textStr andLineColor:(UIColor *)lineColor{
- NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:textStr];
- // 设置删除线样式
- [attributedText addAttribute:NSStrikethroughStyleAttributeName
- value:@(NSUnderlineStyleSingle | NSUnderlinePatternSolid)
- range:NSMakeRange(0, textStr.length)];
- // 设置删除线颜色
- [attributedText addAttribute:NSStrikethroughColorAttributeName
- value:lineColor
- range:NSMakeRange(0, textStr.length)];
- return attributedText;
-
- }
- /// 根据用户信息生成一个富文本(VIP/性别/等级)
- + (NSAttributedString *)createAttributedStringWithUserInfo:(MOUserBase *)userBase{
- NSMutableAttributedString *plainText = [[NSMutableAttributedString alloc] initWithString:@""];
- //加等级
- [self toAddLevelInfoWith:plainText And:userBase.level];
-
- //加性别
- [self toAddGenderImgWith:userBase.userProfile.gender With:plainText];
-
- //加vip
- [self toAddVipInfoWith:plainText And:userBase.vipType];
-
- return plainText;
- }
- + (void)toAddGenderImgWith:(NSInteger)genderNum With:(NSMutableAttributedString *)contentStr{
-
- UIImage *vipImg;
- if(genderNum == 1){
- vipImg = [UIImage imageNamed:@"icon_contact_man"];
- }
- else if (genderNum == 2){
- vipImg = [UIImage imageNamed:@"icon_contact_woman"];
- }
- else{
- return;
- }
-
-
- NSTextAttachment *vipAttachment;
- if(vipImg){
- CGSize vipSize;
- vipAttachment = [[NSTextAttachment alloc] init];
- vipAttachment.image = vipImg;
- //字体行高
- UIFont *font = MOTextLabelFont;
- CGFloat attachmentHeight = font.lineHeight;
- CGFloat imgSizeHeight = GetParamNotZero(vipImg.size.height);
- CGFloat attachmentWidth = attachmentHeight * vipImg.size.width/ imgSizeHeight;
- vipAttachment.bounds = CGRectMake(0, (font.capHeight-font.lineHeight)/2, attachmentWidth, attachmentHeight);
- vipSize = CGSizeMake(attachmentWidth, attachmentHeight);
-
- NSMutableAttributedString *vipImgAttri = [NSMutableAttributedString attachmentStringWithContent:vipImg contentMode:UIViewContentModeScaleAspectFit attachmentSize:vipSize alignToFont:MOTextLabelFont alignment:YYTextVerticalAlignmentCenter];
-
- [vipImgAttri appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
- [contentStr insertAttributedString:[vipImgAttri copy] atIndex:0];
- }
- }
- + (CGFloat)getWidthAboutYYWith:(NSAttributedString *)contentStr
- {
-
- YYTextContainer *container = [YYTextContainer new];
- container.size = CGSizeMake(MAXFLOAT, MAXFLOAT); // 宽度无限制,高度无限制
- container.linePositionModifier = nil; // 可自定义行样式
- // 创建文本布局
- YYTextLayout *layout = [YYTextLayout layoutWithContainer:container text:contentStr];
- // 获取文本高度
- CGSize textSize = layout.textBoundingSize;
- CGFloat textWidth = textSize.width + 1.0;
-
- return textWidth;
- }
- + (void)setStyledTextForLabel:(UILabel *)label
- fullText:(NSString *)text
- targetText:(NSString *)targetText
- color:(UIColor *)color
- hasUnderline:(BOOL)hasUnderline {
-
- if (!label || !text || !targetText) {
- return;
- }
-
- NSMutableAttributedString *attributedString;
-
- // 检查是否已有富文本,如果有则在现有基础上修改,否则创建新的
- if (label.attributedText && label.attributedText.length > 0) {
- // 验证文本内容是否一致
- if ([label.attributedText.string isEqualToString:text]) {
- // 文本一致,在现有富文本基础上修改
- attributedString = [[NSMutableAttributedString alloc] initWithAttributedString:label.attributedText];
- } else {
- // 文本不一致,创建新的富文本
- attributedString = [[NSMutableAttributedString alloc] initWithString:text];
- // 设置整体文本样式
- [attributedString addAttribute:NSFontAttributeName
- value:[UIFont systemFontOfSize:14.0]
- range:NSMakeRange(0, text.length)];
- [attributedString addAttribute:NSForegroundColorAttributeName
- value:[UIColor blackColor]
- range:NSMakeRange(0, text.length)];
- }
- } else {
- // 没有现有富文本,创建新的
- attributedString = [[NSMutableAttributedString alloc] initWithString:text];
- // 设置整体文本样式
- [attributedString addAttribute:NSFontAttributeName
- value:[UIFont systemFontOfSize:14.0]
- range:NSMakeRange(0, text.length)];
- [attributedString addAttribute:NSForegroundColorAttributeName
- value:[UIColor blackColor]
- range:NSMakeRange(0, text.length)];
- }
-
- // 查找目标文本的位置
- NSRange targetRange = [attributedString.string rangeOfString:targetText];
- if (targetRange.location != NSNotFound) {
- // 设置目标文本颜色
- [attributedString addAttribute:NSForegroundColorAttributeName
- value:color
- range:targetRange];
-
- // 添加下划线(如果需要)
- if (hasUnderline) {
- [attributedString addAttribute:NSUnderlineStyleAttributeName
- value:@(NSUnderlineStyleSingle)
- range:targetRange];
- [attributedString addAttribute:NSUnderlineColorAttributeName
- value:color
- range:targetRange];
- } else {
- // 如果不需要下划线,移除可能存在的下划线样式
- [attributedString removeAttribute:NSUnderlineStyleAttributeName range:targetRange];
- [attributedString removeAttribute:NSUnderlineColorAttributeName range:targetRange];
- }
-
- // 存储目标文本范围信息(支持多个范围)
- NSMutableArray *ranges = objc_getAssociatedObject(label, @"targetRanges");
- if (!ranges) {
- ranges = [[NSMutableArray alloc] init];
- }
- [ranges addObject:[NSValue valueWithRange:targetRange]];
- objc_setAssociatedObject(label, @"targetRanges", ranges, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- }
-
- label.attributedText = attributedString;
- }
- + (void)addTapGestureToLabel:(UILabel *)label
- target:(id)target
- action:(SEL)action {
-
- if (!label || !target || !action) {
- return;
- }
-
- // 确保label可以接收用户交互
- label.userInteractionEnabled = YES;
-
- // 移除已存在的手势(避免重复添加)
- for (UIGestureRecognizer *gesture in label.gestureRecognizers) {
- if ([gesture isKindOfClass:[UITapGestureRecognizer class]]) {
- [label removeGestureRecognizer:gesture];
- }
- }
-
- // 添加点击手势
- UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:target action:action];
- [label addGestureRecognizer:tapGesture];
-
- // 存储相关信息
- objc_setAssociatedObject(label, @"target", target, OBJC_ASSOCIATION_ASSIGN);
- objc_setAssociatedObject(label, @"action", NSStringFromSelector(action), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- }
- + (void)setMultipleStyledTextForLabel:(UILabel *)label
- fullText:(NSString *)fullText
- styleConfigs:(NSArray<NSDictionary *> *)styleConfigs {
-
- if (!label || !fullText || !styleConfigs || styleConfigs.count == 0) {
- return;
- }
-
- // 创建初始富文本
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:fullText];
-
- // 设置整体文本样式
- [attributedString addAttribute:NSFontAttributeName
- value:[UIFont systemFontOfSize:14.0]
- range:NSMakeRange(0, fullText.length)];
- [attributedString addAttribute:NSForegroundColorAttributeName
- value:[UIColor blackColor]
- range:NSMakeRange(0, fullText.length)];
-
- NSMutableArray *ranges = [[NSMutableArray alloc] init];
-
- // 遍历所有样式配置
- for (NSDictionary *config in styleConfigs) {
- NSString *targetText = config[@"targetText"];
- UIColor *color = config[@"color"];
- NSNumber *hasUnderlineNum = config[@"hasUnderline"];
-
- if (!targetText || !color || !hasUnderlineNum) {
- continue; // 跳过无效配置
- }
-
- BOOL hasUnderline = [hasUnderlineNum boolValue];
-
- // 查找目标文本的位置
- NSRange targetRange = [fullText rangeOfString:targetText];
- if (targetRange.location != NSNotFound) {
- // 设置目标文本颜色
- [attributedString addAttribute:NSForegroundColorAttributeName
- value:color
- range:targetRange];
-
- // 添加或移除下划线
- if (hasUnderline) {
- [attributedString addAttribute:NSUnderlineStyleAttributeName
- value:@(NSUnderlineStyleSingle)
- range:targetRange];
- [attributedString addAttribute:NSUnderlineColorAttributeName
- value:color
- range:targetRange];
- } else {
- [attributedString removeAttribute:NSUnderlineStyleAttributeName range:targetRange];
- [attributedString removeAttribute:NSUnderlineColorAttributeName range:targetRange];
- }
-
- // 收集范围信息
- [ranges addObject:[NSValue valueWithRange:targetRange]];
- }
- }
-
- // 存储所有范围信息
- objc_setAssociatedObject(label, @"targetRanges", ranges, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
-
- // 设置富文本
- label.attributedText = attributedString;
- }
- + (UILabel *)createFeedbackLabelWithText:(NSString *)text
- feedbackText:(NSString *)feedbackText
- target:(id)target
- action:(SEL)action {
-
- UILabel *label = [[UILabel alloc] init];
- label.numberOfLines = 0;
-
- // 使用新的分离方法设置样式
- [self setStyledTextForLabel:label
- fullText:text
- targetText:feedbackText
- color:[UIColor blueColor]
- hasUnderline:YES];
-
- // 使用新的分离方法添加点击事件
- [self addTapGestureToLabel:label target:target action:action];
-
- return label;
- }
- + (UIFont *)oswaldDemiBoldFont:(CGFloat)size {
- return [self getTheFontWithSize:size AndFontName:kOswaldFontStr];
- }
- + (UIFont *)poppinsLightFont:(CGFloat)size {
- return [self getTheFontWithSize:size AndFontName:kPoppinsLightFontStr];
- }
- + (UIFont *)poppinsRegularFont:(CGFloat)size {
- return [self getTheFontWithSize:size AndFontName:kPoppinsRegularFontStr];
- }
- + (UIFont *)poppinsMediumFont:(CGFloat)size {
- return [self getTheFontWithSize:size AndFontName:kPoppinsMediumFontStr];
- }
- + (UIFont *)poppinsBoldFont:(CGFloat)size {
- return [self getTheFontWithSize:size AndFontName:kPoppinsSemiBoldFontStr];
- }
- + (UIFont *)poppinsSemiBoldFont:(CGFloat)size {
- return [self getTheFontWithSize:size AndFontName:kPoppinsBoldFontStr];
- }
- + (UIFont *)poppinsExtraBoldFont:(CGFloat)size {
- return [self getTheFontWithSize:size AndFontName:kPoppinsExtraBoldFontStr];
- }
- + (UIFont *)poppinskPoppinsMediumItalicFont:(CGFloat)size {
- return [self getTheFontWithSize:size AndFontName:kPoppinsMediumItalicFontStr];
- }
- + (UIFont *)poppinsBoldItalicFont:(CGFloat)size {
- return [self getTheFontWithSize:size AndFontName:kPoppinsBoldItalicFontStr];
- }
- + (UIFont *)lightFont:(CGFloat)size {
- return [UIFont systemFontOfSize:size weight:UIFontWeightLight];
- }
- + (UIFont *)regularFont:(CGFloat)size {
- return [UIFont systemFontOfSize:size weight:UIFontWeightRegular];
- }
- + (UIFont *)mediumFont:(CGFloat)size {
- return [UIFont systemFontOfSize:size weight:UIFontWeightMedium];
- }
- + (UIFont *)boldFont:(CGFloat)size {
- return [UIFont systemFontOfSize:size weight:UIFontWeightBold];
- }
- + (UIFont *)semiboldFont:(CGFloat)size {
- return [UIFont systemFontOfSize:size weight:UIFontWeightSemibold];
- }
- @end
|