ibireme / yytext Goto Github PK
View Code? Open in Web Editor NEWPowerful text framework for iOS to display and edit rich text.
License: MIT License
Powerful text framework for iOS to display and edit rich text.
License: MIT License
如题:
我又设置了
YYTextKeyboardManager *mgr = [YYTextKeyboardManager defaultManager];
[mgr removeObserver:self.textView];
才变的正常了
ps:我把YYTextView加到了tableview的tableHeaderView上
如果使用CocoaPods导入的Swift工程的话,该怎么做呢?
异步编排模式下,表情无法转换吗?求教
抱歉,图片,上传不上来!
创建一个YYTextView() 状态栏就会变成defualt
为什么呢?
我使用的
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return UIStatusBarStyle.LightContent
}
来控制状态栏的。
编辑过程中, 会遇到下面Crash.
Terminating app due to uncaught exception 'NSRangeException', reason: 'NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds'
Code:
- (NSDictionary *)attributesAtIndex:(NSUInteger)index { if (self.length > 0 && index == self.length) index--; return [self attributesAtIndex:index effectiveRange:NULL]; }
YYKit能搜到,为什么呢?
cocoapods version: 0.39.0
添加两个字段,设置字数限制和是否显示剩余字数
pod 'YYWebImage'
pod 'YYKit'
pod 'YYText'
build error :
1.Redefinition of 'YYTextVerticalAlignment'
2.Duplicate interface definition for class 'YYTextRunDelegate'
3.Duplicate interface definition for class 'YYAnimatedImageView'
想把邮箱替换为 @联系人 这种样式的字符串,删除的时候直接删除掉该字符串,但是怎么写正则都不起作用,求教这个正则该怎么写,多谢!!!
// NSString *pattern = @"[-_a-zA-Z@.]+[ ,\n]";
NSString *pattern = @"^[@]+[ ,\n]";
您好。在这个代理方法里面- (void)textViewDidChangeSelection:(YYTextView *)textView,返回回来的selectedRange不准确,具体的说是长按后处于选定状态下,返回的range.length为0,但是按一下空白区域,让蓝色选定状态消失,这次返回的range的结果是正确的,length为选定的文本的长度。
刚刚又试了一下,这个range始终返回的是上一次操作的range
调试时发现:
(void)setMarkedText:(NSString *)markedText selectedRange:(NSRange)selectedRange {
[self _updateIfNeeded];
[self _endTouchTracking];
[self _hideMenu];
if (!NSEqualRanges(_lastTypeRange, _selectedTextRange.asRange)) {
[self _saveToUndoStack];
[self _resetRedoStack];
}
BOOL needApplyHolderAttribute = NO;
if (_innerText.length > 0) {
[self _updateAttributesHolder]; // 这儿,会将设置的属性重置为前面文字的属性
} else {
needApplyHolderAttribute = YES;
}
这样会导致手动设置的属性被重置,不知道是不是故意这样设计的?
添加的代码如下:
YYImage *image = [YYImage imageNamed:imageName];
YYAnimatedImageView *imageView = [[YYAnimatedImageView alloc] initWithImage:image];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5, 2, 38, 16)];
label.text = text;
label.font = [UIFont systemFontOfSize:12];
label.textColor = color;
[imageView addSubview:label];
NSMutableAttributedString *imgText = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeCenter attachmentSize:size alignToFont:[UIFont systemFontOfSize:12] alignment:YYTextVerticalAlignmentBottom];
[_attrText appendAttributedString:imgText];
不知道为什么有的时候这个方法在编辑时不会执行。。执行下删除键就正常执行了
目前好像只能拥有一个textparse
这样的话就需要将许多不同的解析内容全部写到一起,比如:一个textview需要解析自定义emoji也需要解析@xxx
能不能自己写了一个@xxx
解析然和与原来的YYTextSimpleEmoticonParser进行合并使用呢?
Thanks for this great library! In the README example, I found the following codes:
// UIView attachment
UISwitch *switcher = [UISwitch new];
[switcher sizeToFit];
attachment = [NSMutableAttributedString yy_attachmentStringWithContent:switcher contentMode:UIViewContentModeBottom attachmentSize:switcher.frame.size alignToFont:font alignment:YYTextVerticalAlignmentCenter];
[text appendAttributedString: attachment];
However, the UISwitch
is not selectable. How to enable selection of the UISwitch
(or other element like UITextField
)?
应该是把表情符号当做文本处理后进行高度计算了,
如文本:您haidf阿打发士大夫撒地方发的啥方[f024t]法发达范德萨法撒旦法地方
[f024t] 代表一个表情
NSMutableAttributedString *text = [[NSMutableAttributedString alloc]initWithString:txt];
text.yy_font=[UIFont systemFontOfSize:17.0f];
YYTextLinePositionSimpleModifier *modifier = [YYTextLinePositionSimpleModifier new];
modifier.fixedLineHeight = 22.0f;
YYTextContainer *container = [YYTextContainer new];
container.size = CGSizeMake([[UIScreen mainScreen] bounds].size.width * 0.7f-50, CGFLOAT_MAX);
container.linePositionModifier = modifier;
YYTextLayout *layout = [YYTextLayout layoutWithContainer:container text:text ];
实质显示只有3行,计算出来是4行。屏幕宽度320
YYTextEditExample 当文字垂直时,可以试自左向右吗
在iOS7上,输入文字时设置了下划线属性,则无法将其去掉了
https://github.com/ibireme/YYText/blob/master/YYText%2FString%2FYYTextArchiver.m#L245
} else if ([object class] == [_YYCGColor class]) {
_YYCGColor *color = object;
return (id)color.CGColor;
} else if ([object class] == [_YYCGColor class]) {
_YYCGImage *image = object;
return (id)image.CGImage;
}
1、插入图片后,字体会变的很小,好像是一个默认字体。
2、如何获取我插入的附件数组?比如我要输入很多文字,很多图片,最后我要做一个“提交文章”的功能,这些图片我要上传到服务器上。
3、输入很多文字的时候,内存还是会变得很大,有被系统杀掉的风险。
UIStatusBarStyle does not become LightContents after the YYTextEffectWindow.sharedWindow is created.
Do you have a workaround?
你好,我在使用你的YYText框架练习的时候,当我模仿YYTextDemo里边的YYTextAttachmentExample,有qq几个动画,他们使用的是YYImage,每次我引用YYImage,就报错。找不到什么问题,没有重复的YYImageCoder文件名,这文件也没有被链接2次。把YYImage删除后又添加还是不行。Other Linker Flags下边什么都没有。另外这种报错每次遇到都很麻烦,不知道您怎么解决的呢?我只知道看看有没文件名重复,build Phases有没有链接重复,别的都不确定
日志:
Undefined symbols for architecture x86_64:
"_crc32", referenced from:
_yy_png_copy_frame_data_at_index in YYImageCoder.o
-[YYImageEncoder _encodeAPNG] in YYImageCoder.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
比如你微博的Demo,包含有表情,链接,图片这些内容,怎么知道YYLabel要显示的大小,还有怎么进行自动布局呢?
Simply creat a YYTextView:
self.automaticallyAdjustsScrollViewInsets = NO;
YYTextView *textView = [[YYTextView alloc]initWithFrame:CGRectMake(0, 20, self.view.width, 100)];
textView.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.5];
textView.text = @"This is test text";
textView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
[self.view addSubview:textView];
(Sorry failed to upload a screenShot, the text ("this is a test text") can't be seen in textView, and after I type some word, still nothing can be seen including the cursor)
Then I change edgeInset.top to 0.5 and run agin, YYTextView look normal, it also look fine when edgeInset.top was -0.5.
But when edgeInset.top was 0, seems everything just went wrong.
I found you asways set the contentEdge to (64, 0 , 0 , 0) in the Demo, was the contentEdge's top just can't be 0? Or am I miss something?
使用原生 UITextView重写 layoutSubviews方法时调用sizeThatFits获取内容高度以适配 cell,改用了 YYText 后获取的高度始终为0
NSMutableAttributedString *text = [NSMutableAttributedString new];
UIFont *font = [UIFont boldSystemFontOfSize:16];
for (int i = 0; i < tags.count; i++) {
NSString *tag = tags[i];
UIColor *tagStrokeColor = UIColorHex(818e91);
NSMutableAttributedString *tagText = [[NSMutableAttributedString alloc] initWithString:tag];
[tagText yy_insertString:@" " atIndex:0];
[tagText yy_appendString:@" "];
tagText.yy_font = font;
tagText.yy_color = tagStrokeColor;
YYTextBorder *border = [YYTextBorder new];
border.strokeWidth = 1.2f;
border.strokeColor = tagStrokeColor;
border.fillColor = [UIColor clearColor];
border.cornerRadius = 100; // a huge value
border.lineJoin = kCGLineJoinBevel;
border.insets = UIEdgeInsetsMake(1.5, -6, 0, -6);
[tagText yy_setTextBackgroundBorder:border range:[tagText.string rangeOfString:tag]];
[text appendAttributedString:tagText];
}
text.yy_lineSpacing = 0;
text.yy_lineBreakMode = NSLineBreakByCharWrapping;
我的YYLabel 是写在cell上得并且自动布局强制大小的,当我的内容加起来刚好1行以内,就不会报错,而内容大于1行时,YYLabel库里面就直接crash了。
(void)textViewDidChange:(YYTextView *)textView {
NSAttributedString *text = textView.attributedText;
if ([textView.text isEqualToString:@""]) {
text = textView.placeholderAttributedText;
}
CGSize size = CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX);
YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:size text:text];
CGSize newSize = CGSizeMake(layout.textBoundingSize.width, layout.textBoundingSize.height);
NSLog(@"layout.textBoundingSize :%@",NSStringFromCGSize(layout.textBoundingSize));
NSLog(@"self.textView.contentSize :%@",NSStringFromCGSize(self.textView.contentSize));
self.textView.size = newSize;
self.textView.contentSize = newSize;
}
log:
2015-11-26 17:48:49.218 testTextView[8110:1979479] layout.textBoundingSize :{249, 23}
2015-11-26 17:48:49.218 testTextView[8110:1979479] self.textView.contentSize :{240, 50}
测试下来,一些文档没办法显示。比如以下这个文档。
Markdown 語法官方說明繁體中文版.txt
YYText 非常棒,我已经扔掉了 TTTAttributedLabel :D
有个疑问,在文字段落时,行距有时候并没有保持一致,原因不明,见截图:
这是一段很均匀的纯文本(无 emoji 和 Attachment,也没有任何 highlight 和 binding)
仔细看一下会发现,倒数第六行的行距和其他行不同(「。第二,科创版推出...」这一行)
具体原因不明,代码片段:
- (YYLabel *)textLabel
{
if (!textLabel) {
self.textLabel = [[YYLabel alloc] initWithFrame:CGRectZero];
self.textLabel.userInteractionEnabled = YES;
self.textLabel.font = [UIFont systemFontOfSize:kEspressoDescriptionTextFontSize];
self.textLabel.textColor = [UIColor darkGrayColor];
self.textLabel.lineBreakMode = NSLineBreakByCharWrapping;
self.textLabel.textVerticalAlignment = YYTextVerticalAlignmentCenter;
self.textLabel.numberOfLines = 0;
self.textLabel.displaysAsynchronously = YES;
[bubbleView addSubview:self.textLabel];
}
return textLabel;
}
- (YYTextLayout *)textLayoutForMessageContent:(NSString *)content font:(UIFont *)font textWidth:(CGFloat)maxWidth {
NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:content];
text.yy_font = font;
text.yy_color = [UIColor darkGrayColor];
text.yy_lineSpacing = kTextLineSpacing;
text.yy_lineBreakMode = NSLineBreakByCharWrapping;
// 解析超链接
[text enumerateTextParser:AKCTextMessageCheckingTypeURL];
// 解析电话号码
[text enumerateTextParser:AKCTextMessageCheckingTypePhoneNum];
// 解析邮箱地址
[text enumerateTextParser:AKCTextMessageCheckingTypeEmail];
// 解析表情
[text enumerateTextParser:AKCTextMessageCheckingTypeFace];
YYTextContainer *container = [YYTextContainer new];
container.size = CGSizeMake(maxWidth, CGFLOAT_MAX);
YYTextLayout *layout = [YYTextLayout layoutWithContainer:container text:text];
return layout;
}
YYTextLayout *layout = [self textLayoutForMessageContent:msgModel.message_content font:[UIFont systemFontOfSize:16.f] textWidth:maxTextWidth];
width = layout.textBoundingSize.width;
height = layout.textBoundingSize.height;
self.textLabel.frame = CGRectMake(kLeftBubbleTextLeftInset,
kBubbleTextTopInset,
width,
height);
self.textLabel.textLayout = layout;
我的cell并不是需要大量富文本,所以我就直接用YYLbel的基本用法,只是让它异步绘制。代码如下
_requir=[YYLabel new];
_requir.displaysAsynchronously=YES;
_requir.frame=CGRectMake(110, 35, 120, 14);
_requir.backgroundColor=[UIColor redColor];
[self.contentView addSubview:_requir];
_requir.font=kSystemFont(14);
_stock=[[YYLabel alloc]init];
_stock.displaysAsynchronously=YES;
_stock.backgroundColor=[UIColor redColor];
_stock.frame=CGRectMake(110, 60, 120, 14);
[self.contentView addSubview:_stock];
_stock.font=kSystemFont(14);
然后我在setModel的方法里
_requir.text=[NSString stringWithFormat:@"兑换条件:%@",model.convertCondition];
_stock.text=[NSString stringWithFormat:@"剩余:%d份",(int)model.residueNumber];
只有把_stock的高加3也就是17才能显示出来。这是什么情况,我有点摸不着头脑。希望表达清楚了,望解答。
具体报错如下
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_YYAnimatedImageView", referenced from:
objc-class-ref in NSAttributedString+YYText.o
objc-class-ref in YYTextView.o
"_OBJC_CLASS_$_YYImage", referenced from:
objc-class-ref in UIPasteboard+YYText.o
objc-class-ref in YYTextView.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
YYTextContainer *newContainer = _innerContainer.mutableCopy;
这快会Crash.
Log信息:
reason: '-[YYTextContainer mutableCopyWithZone:]: unrecognized selector sent to instance 0x7ff7da64b690'
暂时改为Copy可以用.
实现 intrinsicContentSize 以及 preferredMaxLayoutWidth
使用new / alloc] init] 创建对象,再设置frame属性, YYLabel显示
而直接使用 alloc] initWithFrame 创建对象, YYLabel无法显示
文本超过5K,输入文字就比较卡
给YYlabel做了点击事件,父view上加了一个tap手势,然后YYlabel的事件就不执行了。希望可以解决下这个手势冲突。
When set label's size as textBoundingSize after YYTextLayout, it may cause missing last line when process layoutWithContainer:text:range in display task.
In my code, I've custom a YYLabel contains emoticons, it has a preferred width 232, when use YYTextLayout to calculate size, it returns line count 5 and CGSize(228, 116).
The I set the label's size as (228, 116), when it display, layoutWithContainer:text:range result line count 4.
I can fix this in my own code by keep the label width as preferred width, but it would easy trapped when someone use the textBoundingSize.
is it coming?
比如粗体、颜色这种,甚至附件的包裹
eg : img src=...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.