ios – 非常规形状的NSTextContainer示例?

ios – 非常规形状的NSTextContainer示例?,第1张

概述嗨,我正在使用iOS7的新TextKit API,我正在尝试生成一个不规则形状的UITextView.到目前为止,我在视图控制器中: -(void) loadView{ self.view = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,548)]; NSTextStorage *textStorage = [[NSText 嗨,我正在使用iOS7的新TextKit API,我正在尝试生成一个不规则形状的UITextVIEw.到目前为止,我在视图控制器中:
-(voID) loadVIEw{    self.vIEw = [[UIVIEw alloc] initWithFrame:CGRectMake(0,320,548)];    NSTextStorage *textStorage = [[NSTextStorage alloc] init];    NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];    [textStorage addLayoutManager: layoutManager];    BaseTextContainer *textContainer = [[BaseTextContainer alloc] initWithSize:CGSizeMake(100,100)];    [layoutManager addTextContainer: textContainer];    BaseTextVIEw *textVIEw = [[BaseTextVIEw alloc] initWithFrame:CGRectMake(110,124,100,100) textContainer:textContainer];    textVIEw.backgroundcolor = [UIcolor bluecolor];    textVIEw.editable = YES;    [self.vIEw addSubvIEw:textVIEw];}

然后在我的子类NSTextContainer中,我想将一个mutablePath绘制为文本容器的形状,但不知道如何实现这一点.我有:

- (BOol) isSimpleRectangularTextContainer{    return NO;}- (voID) drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx{    NSLog(@"TEST");    CGContextRef context = ctx;    CGSize layerSize = layer.frame.size;    CGAffinetransform transform = CGAffinetransformMakeScale(layerSize.wIDth / self.initialSize.wIDth,layerSize.height / self.initialSize.height);    CGMutablePathref newGraphicMutablePath = CGPathCreateMutablecopyBytransformingPath(self.mutablePath,&transform);    CGContextAddpath(context,newGraphicMutablePath);    CGPathRelease(newGraphicMutablePath);    CGContextSetFillcolorWithcolor(context,[UIcolor redcolor].CGcolor);    CGContextDrawPath(context,kCGPathFill);}

对于如何使其工作有点困惑.我找不到具有不规则形状的NSTextContainer的任何示例.

解决方法 不需要构建Text Kit堆栈的所有代码,因为您没有修改堆栈的体系结构.刚开始使用普通的UITextVIEw – 假设它是self.textVIEw – 然后将一个或多个UIBezIErPath对象分配给它的排除路径:
self.tv.textContainer.exclusionPaths = myArrayOfBezIErPaths;

这些路径是排除路径,因此对于椭圆,您将需要创建四条路径,每条路径描述文本容器的一个角.

或者,您可以自己构建Text Kit堆栈,以便插入自己的文本容器子类,并通过重写lineFragmentForProposedRect:来修改允许文本的位置,也许类似于我在此处执行的 *** 作:https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch10p537exclusionPath2/ch23p813textKitShapes/MyTextContainer.swift

一些实验:

总结

以上是内存溢出为你收集整理的ios – 非常规形状的NSTextContainer示例?全部内容,希望文章能够帮你解决ios – 非常规形状的NSTextContainer示例?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1100344.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存