12207480 / tyattributedlabel Goto Github PK
View Code? Open in Web Editor NEWTYAttributedLabel 简单,强大的属性文本控件(无需了解CoreText),支持图文混排显示,支持添加链接,image和UIView控件,支持自定义排版显示
License: MIT License
TYAttributedLabel 简单,强大的属性文本控件(无需了解CoreText),支持图文混排显示,支持添加链接,image和UIView控件,支持自定义排版显示
License: MIT License
当lineBreakMode设置为kCTLineBreakByTruncatingMiddle时没有效果,希望能处理下。
如题,貌似不支持...
CTTextAlignment textAlignment:
typedef CF_ENUM(uint8_t, CTTextAlignment) {
kCTTextAlignmentLeft CT_ENUM_AVAILABLE(10_8, 6_0) = 0,
kCTTextAlignmentRight CT_ENUM_AVAILABLE(10_8, 6_0) = 1,
kCTTextAlignmentCenter CT_ENUM_AVAILABLE(10_8, 6_0) = 2,
kCTTextAlignmentJustified CT_ENUM_AVAILABLE(10_8, 6_0) = 3,
kCTTextAlignmentNatural CT_ENUM_AVAILABLE(10_8, 6_0) = 4,
}
CTLineBreakMode lineBreakMode:
typedef CF_ENUM(uint8_t, CTLineBreakMode) {
kCTLineBreakByWordWrapping = 0,
kCTLineBreakByCharWrapping = 1,
kCTLineBreakByClipping = 2,
kCTLineBreakByTruncatingHead = 3,
kCTLineBreakByTruncatingTail = 4,
kCTLineBreakByTruncatingMiddle = 5
};
请问下 把URL链接替换成 [网页] 这两个字具体是怎样实现的呢(官方新浪微博就是这样做的) ???
并且 长按 [网页] 能弹出系统自带的剪贴板View 点击复制能够copyURL,并不是网页二字.
我想了很久(能力不够),还是没有实现出来这样的效果,不知能各位大牛能否提供多种思路??
lineBreakMode设置为CTLineBreakByTruncatingTail,会全部都只有一行了
现在给TYImageStorage设置size,并不是把大小设置成固定的,而是根据实际图片的宽高比。
现在我有设置图片固定大小的需求,要怎么实现呢?
比如我里面一些评论开头是名字 名字长度要限制 超过的要截断 能通过一些方法来进行这项设置么
阿拉伯语 和 图片混排会 CTRun的range 会计算错误 造成图片和文字叠加的bug。
用 boundingRectWithSize 计算的高度不对,因为还有行间距问题!
图文混排时,想实现 图片 比 文字 宽一些, 因为文字两侧想留部分间隔
不知道,这样 除了 masksToBounds 还有什么较好的方式
现在遇到一个业务需求,就是标题和正文之间要有较大的行距,但是正文的行与行只用默认间距。如果标题是多行的话也用默认间距就行。
行间距设成0以后,还是觉的大了,设成负的也不管用,想问下,还有别的方法可以设置吗?谢谢
文字后面会添加"\n"用来换行,不加就没有问题,添加了就会出现这个问题。
问题如下:
![simulator screen shot 2016 6 2 9 41 56](https://cloud.githubusercontent.com/assets/12853558/15731344/eee21b2a-28a6-11e6-9fce-bc2624b8e034.png
代码:
如题。
个人感觉秦风毒萝更萌!
NSLineBreakByTruncatingMiddle 等 都可以 但是设置 NSLineBreakByTruncatingTail 无效
Why not use M80AttributedLabel?Repeat things.
console print these:
1:
2015-11-05 11:29:05.152 TYAttributedLabelDemo[24130:907]
-[ViewController setEdgesForExtendedLayout:]: unrecognized selector sent to instance 0x1d599fb0
2015-11-05 11:29:05.156 TYAttributedLabelDemo[24130:907]
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController setEdgesForExtendedLayout:]: unrecognized selector sent to instance 0x1d599fb0'
2:
2015-11-05 11:36:58.926 TYAttributedLabelDemo[24237:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TExamTextField setTintColor:]: unrecognized selector sent to instance 0x1ed3a860'
3:
2015-11-05 11:38:41.877 TYAttributedLabelDemo[24308:907] -[UITableView setEstimatedRowHeight:]: unrecognized selector sent to instance 0x2038a800
2015-11-05 11:38:41.880 TYAttributedLabelDemo[24308:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableView setEstimatedRowHeight:]: unrecognized selector sent to instance 0x2038a800'
label.lineBreakMode = kCTLineBreakByTruncatingMiddle;
label1.lineBreakMode = kCTLineBreakByTruncatingHead;
以上两项设置,只能显示1行文字
// 跟帖数
TYAttributedLabel *numLabel = [[TYAttributedLabel alloc]initWithFrame:CGRectMake(10, frameY, kScreenWidth-10-10, 20)];
numLabel.textAlignment = kCTTextAlignmentRight;
numLabel.backgroundColor = [UIColor redColor];
TYImageStorage *numStorage = [[TYImageStorage alloc]init];
numStorage.cacheImageOnMemory = YES;
numStorage.imageName = @"post_s";
numStorage.size = CGSizeMake(18, 18);
numStorage.imageAlignment = TYImageAlignmentRight;
[numLabel appendTextStorage:numStorage];
[numLabel appendText:@" "];
NSMutableAttributedString *numString = [[NSMutableAttributedString alloc]initWithString:_activityDataModel.num];
[numString setFont:[UIFont fruitdayLightGaryText]];
[numString setTextColor:[UIColor fruitdayLightGaryText]];
[numString addAttributeCharacterSpacing:0];
[numString addAttributeAlignmentStyle:kCTTextAlignmentRight lineSpaceStyle:0 lineBreakStyle:kCTLineBreakByTruncatingTail];
[numLabel appendTextAttributedString:numString];
[numLabel sizeToFit];
[_headView addSubview:numLabel];
如过我不加上面的图片 就可以正确的右对齐,加了之后就一直显示左对齐了
RT
ios9上中文双引号显示与ios8不一样的问题想到解决办法没? 找了好几天了,没找到
@Property (weak, nonatomic) IBOutlet TYAttributedLabel *timeButtonLabel;
[self.timeButtonLabel setAttributedText:totalString];
self.timeButtonLabel.textAlignment = NSTextAlignmentCenter;//NSTextAlignmentCenter不起作用
你好,现在使用系统自带键盘输入表情显示为?问号。该如何处理,说明一下思路也可以,项目紧急,先谢谢了
青春励志: 其实所有漂泊的人,不过是为了有一天能够不再漂泊,能用自己的力量撑起身后的家人和自己爱的人.青春励志
大神,能复制整个文本么
如题,比如我有一个文字表情 [大哭], 在Label中怎么显示对应的图片? 你那边有没有Demo,有的话,请发给我一个,不剩感激。。 [email protected]
简单修改了singletap方法,不知有没有更好的方法
(void)singleTap:(UITapGestureRecognizer *)sender
{
CGPoint point = [sender locationInView:self];
// CoreText context coordinates are the opposite to UIKit so we flip the bounds
CGAffineTransform transform = CGAffineTransformScale(CGAffineTransformMakeTranslation(0, self.bounds.size.height), 1.f, -1.f);
__typeof (self) __weak weakSelf = self;
__block BOOL didHit = NO;
// 遍历run位置字典
[_runRectDictionary enumerateKeysAndObjectsUsingBlock:^(NSValue *keyRectValue, id obj, BOOL *stop) {
CGRect imgRect = [keyRectValue CGRectValue];
CGRect rect = CGRectApplyAffineTransform(imgRect, transform);
// point 是否在rect里
if(CGRectContainsPoint(rect, point)){
//NSLog(@"点击了 textStorage ");
// 调用代理
if (_delegateFlags.textStorageClickedAtPoint) {
didHit = YES;
[_delegate attributedLabel:weakSelf textStorageClicked:obj atPoint:point];
*stop = YES;
}
}
}];
if (!didHit) {
if ([_delegate respondsToSelector:@selector(attributedLabelDidNotHit)]) {
[_delegate attributedLabelDidNotHit];
}
}
}
(void)setLineBreakMode:(CTLineBreakMode)lineBreakMode
{
if (_lineBreakMode != lineBreakMode) {
_lineBreakMode = lineBreakMode;
if (_lineBreakMode == kCTLineBreakByTruncatingTail)
{
lineBreakMode = _numberOfLines == 1 ? kCTLineBreakByCharWrapping : kCTLineBreakByWordWrapping;
}
[_attString addAttributeAlignmentStyle:_textAlignment lineSpaceStyle:_linesSpacing paragraphSpaceStyle:_paragraphSpacing lineBreakStyle:lineBreakMode];
[self resetFrameRef];
}
}
为什么要这么处理 linBreakMode 呢? 如果我想要 kCTLineBreakByTruncatingTail 这种效果, 可以注释掉 这个 if 判断么?
怎样移除 TYAttributedLabel里的所有 重新添加
据说CALayer可以异步渲染 那个。。。加好友 企鹅?
重新设置文本信息,本来设置的多行,重新设置文本后一行
可以支持文字竖排么
在xcode7.1,iOS9模拟器上,简单文本显示的例子中,label1只显示到"面对着汹涌而来的现实,觉..."这里,后面的文本被截断了.
如何添加阴影效果呀
使用xib的autolayout来创建label怎么可以限制文本内容只显示一行,怎么在后面加上...省略号呢?
添加了
labell.numberOfLines = 1;
label.lineBreakMode = kCTLineBreakByTruncatingTail;
还是不行,省略号没有显示出来,谢谢!
TYAttributedLabel *label1 = [[TYAttributedLabel alloc]initWithFrame:CGRectMake(0, 64, 320, 110)];
TYImageStorage *imageUrlStorage = [[TYImageStorage alloc]init];
imageUrlStorage.imageURL = [NSURL URLWithString:@"https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png"];
imageUrlStorage.size = CGSizeMake(15,15);
imageUrlStorage.placeholdImageName = @"loading";
[label1 appendTextStorage:imageUrlStorage];
[label1 appendTextAttributedString:[[NSMutableAttributedString alloc]initWithString:@" "]];
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:@"sdflsdjgljsdlgjlsjglsdjlkfgjsdjglsdjgkjsgjsjglsjdgkgkjsgjgjlgjlgjdsfsdfdsgdsgjkdlsjgklsjdgkjsdljglsdjgkjdfslgjfkdgjljglksjdlgjs"];
[label1 appendTextAttributedString:attributedString];
// 文字间隙
label1.characterSpacing = 2;
// 文本行间隙
label1.linesSpacing = 2;
label1.lineBreakMode = kCTLineBreakByTruncatingTail;
label1.numberOfLines = 2;
// 文本字体
label1.font = [UIFont systemFontOfSize:17];
[self.view addSubview:label1];
label的多行设置失效.总是显示一行
使用Masonry时,TYAttributedLabel必须指定高度,否则无法显示,且sizeToFit失效.不知道是自己的代码问题,还是楼主没有做到兼容.求解答啊 在线等 急求!!!!谢楼主,楼主威武霸气!
设置文本颜色大小时 并没有给出range的入口 我看了你的源码 range都是[0,self.lengh]
出现一行文字大小不一样或者颜色不一样的时候我还要自己去更改
能不能直接添加进来
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.