Skip to content

VVRichText 是一个异步富文本显示,编辑组件、支持点击、等事件

Notifications You must be signed in to change notification settings

chinaxxren/VVRichText

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

96 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VVRichText

关于

  1. VVRichText 支持富文本显示,支持异步文本渲染。
  2. 可以在文本中插入本地图片,网络图片或UIView对象。
  3. 支持WebP、GIF等格式。
  4. 支持添加单击和长按事件到文本、图片。
  5. 绘制文本框架,绘制空心字,设置文本垂直对齐属性等。
  6. 解析文本中的表达式,如http(s)链接、@user、#theme#、电话号码。
  7. 快速设置图像角半径属性和模糊处理等。
  8. 支持布局控制多个图文元素
  9. 支持SDWebImage缓存库
文字对象例子 TextWidget
  • Feed正文内容模型
VVTextWidget *contentTextWidget = [VVTextWidget new];
contentTextWidget.maxNumberOfLines = 0;
contentTextWidget.text = statusModel.content;
contentTextWidget.font = [UIFont systemFontOfSize:15.0f];
contentTextWidget.textColor = VV_COLOR(40, 40, 40, 1);
contentTextWidget.frame = CGRectMake(nameTextWidget.left, nameTextWidget.bottom + 10.0f, VV_SCREEN_WIDTH - 80.0f, CGFLOAT_MAX);
// 添加长按复制
[contentTextWidget vv_addLongPressActionWithData:contentTextWidget.text
                                  highLightColor:VV_COLOR(0, 0, 0, 0.25f)];
// 解析表情、主题、网址
[VVTextParser parseGeneralEmojiWithTextWidget:contentTextWidget];
[VVTextParser parseTopicWithVVTextWidget:contentTextWidget
                               linkColor:VV_COLOR(113, 129, 161, 1)
                          highlightColor:VV_COLOR(0, 0, 0, 0.15)];
[VVTextParser parseHttpURLWithTextWidget:contentTextWidget
                               linkColor:VV_COLOR(113, 129, 161, 1)
                          highlightColor:VV_COLOR(0, 0, 0, 0.15f)];
图片对象例子 ImageWidget
  • Feed头像模型
VVImageWidget *avatarWidget = [[VVImageWidget alloc] initWithIdentifier:AVATAR_IDENTIFIER];
if (statusModel.avatar) {
    avatarWidget.contents = statusModel.avatar;
} else {
    avatarWidget.contents = [UIImage imageNamed:@"defaultavatar.png"];
}
avatarWidget.cornerRadius = 20.0f;
avatarWidget.cornerBackgroundColor = [UIColor whiteColor];
avatarWidget.backgroundColor = [UIColor whiteColor];
avatarWidget.frame = CGRectMake(10.0f, 20.0f, 40.0f, 40.0f);
avatarWidget.tag = 9;
avatarWidget.cornerBorderWidth = 1.0f;
avatarWidget.cornerBorderColor = [UIColor grayColor];
  • 将图片和文字的Widget对象添加到VVWidgetCollect中
[self addWidget:nameTextWidget];
[self addWidget:contentTextWidget];
  • Cell高度计算
self.height = [self suggestHeightWithBottomMargin:15.0f];
  • 单独更新一个Cell异步线程渲染会闪烁,切换为主线程渲染,比如点击展开Feed正文
//展开Cell
- (void)openTableViewCell:(FeedCell *)cell {
    NSInteger row = cell.indexPath.row;
    [self.feedVM expendData:row];
    [self reloadCell:row];
}

// 异步线程渲染会闪烁,切换为主线程渲染
- (void)reloadCell:(NSInteger)row {
    self.asynDisplay = NO;

    [self.tableView beginUpdates];
    [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:row inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
    [self.tableView endUpdates];

    self.asynDisplay = YES;
}

集成

  • 通过pod 'VVRichText'集成到项目中

About

VVRichText 是一个异步富文本显示,编辑组件、支持点击、等事件

Resources

Stars

Watchers

Forks

Packages

No packages published