{"action":"created","issue":{"url":"https://api.github.com/repos/ibireme/YYText/issues/433","repository_url":"https://api.github.com/repos/ibireme/YYText","labels_url":"https://api.github.com/repos/ibireme/YYText/issues/433/labels{/name}","comments_url":"https://api.github.com/repos/ibireme/YYText/issues/433/comments","events_url":"https://api.github.com/repos/ibireme/YYText/issues/433/events","html_url":"https://github.com/ibireme/YYText/issues/433","id":169037989,"number":433,"title":"Emoji显示不全","user":{"login":"xclidongbo","id":10287985,"avatar_url":"https://avatars.githubusercontent.com/u/10287985?v=3","gravatar_id":"","url":"https://api.github.com/users/xclidongbo","html_url":"https://github.com/xclidongbo","followers_url":"https://api.github.com/users/xclidongbo/followers","following_url":"https://api.github.com/users/xclidongbo/following{/other_user}","gists_url":"https://api.github.com/users/xclidongbo/gists{/gist_id}","starred_url":"https://api.github.com/users/xclidongbo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xclidongbo/subscriptions","organizations_url":"https://api.github.com/users/xclidongbo/orgs","repos_url":"https://api.github.com/users/xclidongbo/repos","events_url":"https://api.github.com/users/xclidongbo/events{/privacy}","received_events_url":"https://api.github.com/users/xclidongbo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-08-03T03:13:42Z","updated_at":"2016-08-12T07:32:00Z","closed_at":null,"body":"有时候的Emoji表情显示不全."},"comment":{"url":"https://api.github.com/repos/ibireme/YYText/issues/comments/239380181","html_url":"https://github.com/ibireme/YYText/issues/433#issuecomment-239380181","issue_url":"https://api.github.com/repos/ibireme/YYText/issues/433","id":239380181,"user":{"login":"xclidongbo","id":10287985,"avatar_url":"https://avatars.githubusercontent.com/u/10287985?v=3","gravatar_id":"","url":"https://api.github.com/users/xclidongbo","html_url":"https://github.com/xclidongbo","followers_url":"https://api.github.com/users/xclidongbo/followers","following_url":"https://api.github.com/users/xclidongbo/following{/other_user}","gists_url":"https://api.github.com/users/xclidongbo/gists{/gist_id}","starred_url":"https://api.github.com/users/xclidongbo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xclidongbo/subscriptions","organizations_url":"https://api.github.com/users/xclidongbo/orgs","repos_url":"https://api.github.com/users/xclidongbo/repos","events_url":"https://api.github.com/users/xclidongbo/events{/privacy}","received_events_url":"https://api.github.com/users/xclidongbo/received_events","type":"User","site_admin":false},"created_at":"2016-08-12T07:32:00Z","updated_at":"2016-08-12T07:32:00Z","body":"我贴上代码来说明吧:\r\n我是用tableView来做聊天列表的.\r\n以下是我在cell中的代码:\r\n```\r\n//根据不同model类来获取一个NSMutableAttributedString类型的类来展示.\r\n- (NSMutableAttributedString *)configureChatWithModel:(PublicChatModel *)model {\r\n    \r\n    self.backView.backgroundColor = [UIColor colorWithRGB:0x000000 alpha:0.4];\r\n    self.model = model;\r\n    NSMutableAttributedString * text = [NSMutableAttributedString new];\r\n\r\n    [text appendAttributedString:[self attributeWithLevel:model.level]];\r\n    [text appendAttributedString:[[NSAttributedString alloc] initWithString:@\" \"]];\r\n    [text appendAttributedString:[self attributeWithNickname:model.user_nicename color:UIColorWithRGB(0xffd600)]];\r\n    [text appendAttributedString:[[NSAttributedString alloc] initWithString:@\" \"]];\r\n    [text appendAttributedString:[self attributeWithMessage:[NSString stringWithFormat:@\": %@\",model.message] color:[UIColor whiteColor]]];\r\n    return text;\r\n}\r\n\r\n//等级图片的NSMutableAttributedString\r\n- (NSMutableAttributedString *)attributeWithLevel:(NSString *)level {\r\n    UIImage * image = [self imageWithLevel:level];\r\n    NSMutableAttributedString * attributeStr = [NSMutableAttributedString yy_attachmentStringWithContent:image contentMode:UIViewContentModeCenter attachmentSize:CGSizeMake(image.size.width, image.size.height) alignToFont:[UIFont systemFontOfSize:kMessageFont] alignment:YYTextVerticalAlignmentCenter];\r\n    return attributeStr;\r\n}\r\n\r\n//昵称的NSMutableAttributedString\r\n- (NSMutableAttributedString *)attributeWithNickname:(NSString *)nickname color:(UIColor *)color {\r\n    \r\n    NSMutableAttributedString * text = [[NSMutableAttributedString alloc] initWithString:nickname attributes:@{NSForegroundColorAttributeName:color,\r\n          NSFontAttributeName:[UIFont systemFontOfSize:kMessageFont]\r\n        }];\r\n    if (text.length>9) {\r\n        [text replaceCharactersInRange:NSMakeRange(9, text.length-9) withString:@\"...\"];\r\n    }\r\n    \r\n    @weakify(self);\r\n    [text yy_setTextHighlightRange:text.yy_rangeOfAll color:UIColorWithRGB(0xffd600) backgroundColor:[UIColor grayColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {\r\n//        DDLogDebug(@\"Tap header %@\",self.model.uid);\r\n        @strongify(self);\r\n        if (_tapGRBlock) {\r\n            _tapGRBlock(self.model.uid);\r\n        }\r\n        \r\n    }];\r\n    \r\n    return text;\r\n}\r\n\r\n//有可能是文字或者表情的NSMutableAttributedString\r\n- (NSMutableAttributedString *)attributeWithMessage:(NSString *)message color:(UIColor *)color{\r\n    NSMutableAttributedString * text = [[NSMutableAttributedString alloc] initWithString:message attributes:@{NSForegroundColorAttributeName:color,\r\n        NSFontAttributeName:[UIFont systemFontOfSize:kMessageFont]\r\n        }];\r\n    return text;\r\n}\r\n\r\n\r\n//cell的初始化.\r\n- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {\r\n    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];\r\n    if (self) {\r\n        [self configureView];\r\n    }\r\n    return self;\r\n}\r\n\r\n//初始化的细节.其中chatLabel是yylabel.\r\n- (void)configureView {\r\n    \r\n    UIView * contentView = self.contentView;\r\n    self.backView = [UIView new];\r\n    self.backgroundColor = [UIColor clearColor];\r\n    contentView.backgroundColor = [UIColor clearColor];\r\n    \r\n    self.backView.backgroundColor = [UIColor colorWithWhite:0.000 alpha:0.4];\r\n    self.backView.layer.cornerRadius = 5;\r\n    [contentView addSubview:_backView];\r\n    \r\n    CGFloat selfWidth = CGRectGetWidth(self.frame);\r\n    self.backView.frame = CGRectMake(0, 2.5, selfWidth, 10);\r\n    \r\n    self.chatLabel = [[YYLabel alloc] init];\r\n    self.chatLabel.font = [UIFont systemFontOfSize:kMessageFont];\r\n    [self.backView addSubview:self.chatLabel];\r\n    self.chatLabel.numberOfLines = 0;\r\n    self.chatLabel.textVerticalAlignment = YYTextVerticalAlignmentTop;\r\n    self.chatLabel.textAlignment = NSTextAlignmentLeft;\r\n    self.chatLabel.preferredMaxLayoutWidth = CGRectGetWidth(self.bounds)-14;\r\n    \r\n    self.chatLabel.frame = CGRectMake(7, 6, selfWidth-14, 10);\r\n    \r\n}\r\n\r\n//该方法是cell中model类的赋值.\r\n- (void)setValueWithModel:(PublicChatModel *)model {\r\n    \r\n    NSMutableAttributedString * text ;\r\n    switch (model.isBarrageOpen) {\r\n        case NSMessageTypePublicChat: {\r\n            text = [self configureChatWithModel:model];\r\n            break;\r\n        }\r\n        case NSMessageTypeBarrage: {\r\n            text = [self configureChatWithModel:model];\r\n            break;\r\n        }\r\n        case NSMessageTypeGift: {\r\n            text = [self configureGiftWithModel:model];\r\n            break;\r\n        }\r\n        case NSMessageTypeSystem: {\r\n            \r\n            break;\r\n        }\r\n    }\r\n    self.chatLabel.preferredMaxLayoutWidth = CGRectGetWidth(self.bounds)-14;\r\n    self.chatLabel.numberOfLines = 0;\r\n    CGFloat selfWidth = CGRectGetWidth(self.bounds);\r\n    CGSize size = CGSizeMake(selfWidth-14, CGFLOAT_MAX);\r\n    text.yy_alignment = NSTextAlignmentLeft;\r\n    text.yy_font = [UIFont systemFontOfSize:kMessageFont];\r\n    text.yy_lineSpacing = 1;\r\n    \r\n    self.chatLabel.attributedText = text;\r\n\r\n    YYTextLayout * layout = [YYTextLayout layoutWithContainerSize:size text:text];\r\n    CGRect layoutFrame = layout.textBoundingRect;\r\n    \r\n    self.chatLabel.frame = CGRectMake(7, 6, CGRectGetWidth(layoutFrame), CGRectGetHeight(layoutFrame));\r\n    self.backView.frame = CGRectMake(0, 2.5, CGRectGetWidth(layoutFrame)+14, CGRectGetHeight(layoutFrame)+12);\r\n    \r\n    \r\n}\r\n\r\n```\r\n每个cell 展示的内容有 : 等级图片+名字+公聊内容.\r\n现在发现的问题是:\r\n如果等级图片和名字的长度正好占一行,那么公聊内容就不显示全是\"...\"\r\n这个不知道有什么解决办法没.\r\n目前应急方法是我把名字的长度做了限制,导致等级图片+名字的长度不满一行,这样公聊内容才能显示."}}
{"actor":{"display_login":"xclidongbo"}}