cttexttab.h学习

Text Tab Types Text Tab Constants Text Tab Creation Text Tab Access学习

1.Text Tab Types

1
CFTypeID CTTextTabGetTypeID( void ) CT_AVAILABLE(10_5, 3_2);

2.Text Tab Constants

1
CT_EXPORT const CFStringRef kCTTabColumnTerminatorsAttributeName CT_AVAILABLE(10_5, 3_2);

3.Text Tab Creation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
-(void)drawRect:(CGRect)rect{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetTextMatrix(context , CGAffineTransformIdentity);
CGContextTranslateCTM(context , 0 ,self.bounds.size.height);
CGContextScaleCTM(context, 1.0 ,-1.0);
///制表符前后都要有空格,生效。
NSMutableAttributedString *mabstring = [[NSMutableAttributedString alloc]initWithString:@"wenjie t 322.2 t 2.22 t 3.33 n 京晓 t 5.27 t 2.4 t 32.43"];
NSMutableDictionary * dic=[NSMutableDictionary dictionary];
CFCharacterSetRef setRef = CFCharacterSetGetPredefined(kCFCharacterSetLowercaseLetter);
[dic setObject:(__bridge id _Nonnull)(setRef) forKey:(__bridge NSString *)kCTTabColumnTerminatorsAttributeName];
CTTextTabRef textTab = CTTextTabCreate(
kCTTextAlignmentLeft,
100,
(__bridge CFDictionaryRef)dic);
NSDictionary * dicTextTab = (__bridge NSDictionary * )CTTextTabGetOptions(textTab);
NSLog(@"dic textTab %@",dicTextTab);
CTTextTabRef textTab1 = CTTextTabCreate(
kCTTextAlignmentCenter,
100,
NULL);
NSMutableArray * arr= [NSMutableArray array];
UIView * view= [[UIView alloc]initWithFrame:CGRectMake(50, 0, 100, 20)];
view.backgroundColor = [UIColor redColor];
[self addSubview: view];
[arr addObject:(__bridge id)textTab];
[arr addObject:(__bridge id)textTab1];
CGFloat tab = 50;
CTParagraphStyleSetting setting[2] ;
setting[0].spec = kCTParagraphStyleSpecifierTabStops;
setting[0].value =&arr;
setting[0].valueSize = sizeof(CFArrayRef);
setting[1].spec = kCTParagraphStyleSpecifierDefaultTabInterval;
setting[1].value =&tab;
setting[1].valueSize = sizeof(CGFloat);
CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(setting, 2);
dic = [NSMutableDictionary dictionary];
[dic setObject:(__bridge id)paragraphStyle forKey:(__bridge NSString *)kCTParagraphStyleAttributeName];
[ mabstring setAttributes:dic range:NSMakeRange(0, mabstring.length)];
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)mabstring);
CGMutablePathRef Path = CGPathCreateMutable();
CGPathAddRect(Path, NULL ,CGRectMake(10 , 40 ,self.bounds.size.width-10 , self.bounds.size.height-60));
CFRange range = CFRangeMake(0, 0);
CTFrameRef frame = CTFramesetterCreateFrame(framesetter,range, Path, NULL);
CTFrameDraw(frame,context);
}

效果:

image

这个虽然影响制表符 但是没有明显的规律可以查询。

4.Text Tab Access