我试图CTFontCreateWithNameAndOptions()从CoreText 使用,链接器说"未找到符号",专门用于_CTFontCreateWithNameAndOptions.我添加了CoreText.framework并导入<CoreText/CoreText.h>.它编译得很好,但链接器失败了.
这是CTFont.h中的声明:
CTFontRef CTFontCreateWithNameAndOptions(
CFStringRef name,
CGFloat size,
const CGAffineTransform *matrix,
CTFontOptions options ) CT_AVAILABLE_STARTING( __MAC_10_6, __IPHONE_3_2);
这是实际的电话:
CTFontRef font = CTFontCreateWithNameAndOptions( (CFStringRef)@"HelveticaNeue-Bold" , 14.0f , NULL , kCTFontOptionsDefault ) ;
有人有什么想法吗?
我的iOS应用程序链接到4.2框架.
为什么以下代码忽略了空格? 
UIColor *textColor = [UIColor colorWithRed:153.0/255.0 green:102.0/255.0 blue:51.0/255.0 alpha:1.0];
CGContextSetFillColorWithColor(ctx, [textColor CGColor]);
CGContextSelectFont(ctx, "Helvetica Neue Bold" , 14, kCGEncodingMacRoman);
CGContextSetTextMatrix(ctx, CGAffineTransformMakeScale(1, -1));
CGContextSetShadowWithColor(ctx, CGSizeMake(0.0, 1.0), 1.0, [[UIColor whiteColor] CGColor]);
//CGContextSetAllowsAntialiasing(ctx, YES);
NSString *str = @"test1 test2";
CGContextShowTextAtPoint(ctx, 5, 17, [str UTF8String], str.length);
Run Code Online (Sandbox Code Playgroud)
将字体名称更改为"Helvetica Neue"会产生空白区域: 
有谁知道这里发生了什么?
我有一定数量的文字填补了一些CTFrame(不止一个).要创建所有框架(每页一个),我将填充一个框架,获取未使用框架的文本CTFrameGetVisibleStringRange并重复此过程,直到处理完所有文本.
在除最后一帧之外的所有帧上,文本占据页面的相同高度.在最后一帧,我想知道文本占据的真实高度,知道我可以在哪里开始绘制更多文本.
有没有办法做到这一点?
UPDATE
根据评论的要求,这是我使用@omz建议的解决方案:
我在我的项目中使用ARC:
CTFrameRef locCTFrame = (__bridge CTFrameRef)ctFrame;
//Save CTLines
lines = (NSArray *) ((__bridge id)CTFrameGetLines(locCTFrame));
//Get line origins
CGPoint lOrigins[MAXLINESPERPAGE];
CTFrameGetLineOrigins(locCTFrame, CFRangeMake(0, 0), lOrigins);
CGFloat colHeight = self.frame.size.height;
//Save the amount of the height used by text
percentFull = ((colHeight - lOrigins[[lines count] - 1].y) / colHeight);
Run Code Online (Sandbox Code Playgroud) 我正在编写一个使用自定义字体(CTFontManagerRegisterFontsForURL)的IOS程序。我加载字体,将其添加为字符串属性,创建框架设定器,然后创建框架,并将其绘制到上下文中。我释放我使用的所有东西。仪器没有发现泄漏,但:
使用此功能时,应用程序使用的内存会增加而不会减少。离开功能时,字体的保留计数为2。
这是代码:
CFMutableAttributedStringRef attributedStringRef = CFAttributedStringCreateMutable(kCFAllocatorDefault, 0);
CFAttributedStringBeginEditing(attributedStringRef);
CFAttributedStringReplaceString(attributedStringRef, CFRangeMake(0, 0), (CFStringRef)label.text);
font = CTFontCreateWithName((CFStringRef)label.fontName, label.fontHeight, NULL);
Run Code Online (Sandbox Code Playgroud)
保留字体数:1
CFAttributedStringSetAttribute(attributedStringRef, CFRangeMake(0, label.text.length), kCTFontAttributeName, font);
CFAttributedStringEndEditing(attributedStringRef);
Run Code Online (Sandbox Code Playgroud)
保留字体数:2
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddRect(path, NULL, rect);
CFRelease(font);
Run Code Online (Sandbox Code Playgroud)
保留字体数:1
CTFramesetterRef frameSetter = CTFramesetterCreateWithAttributedString(attributedStringRef);
Run Code Online (Sandbox Code Playgroud)
保留字体数:3
CFRelease(attributedStringRef);
CTFrameRef frame = CTFramesetterCreateFrame(frameSetter,
CFRangeMake(0, 0),
path, NULL);
Run Code Online (Sandbox Code Playgroud)
保留字体数:5
CFRelease(frameSetter);
Run Code Online (Sandbox Code Playgroud)
保留字体数:4
CTFrameDraw(frame, ctx);
CFRelease(frame);
Run Code Online (Sandbox Code Playgroud)
保留字体数:2
CGPathRelease(path);
Run Code Online (Sandbox Code Playgroud)
是否有某种缓存?我真的需要立即清除此字体使用的内存。
PS:我使用CFGetRetainCount来获取字体的保留计数。
谢谢 !
我们有一个适用于iOS的应用程序,可以呈现大量文本:http://itunes.apple.com/br/app/biblia-sagrada/id370178518?mt = 8
我们使用CoreText渲染文本,并让用户能够更改格式,字体大小和字体.
我们正在尝试将其移植到Android,但我不确定Android中是否有替代CoreText.
我想UITextView在用户输入时为可编辑文本添加轮廓或笔划.完全像模因:http://t.qkme.me/3oi5rs.jpg

我必须使用,UITextView因为我需要多线支持.我已经尝试了所有的方法,并得出了我必须使用的结论CoreText.我几乎所有的解决方案都在工作,但是卡在textview文本中的文本卡住了.我drawRect在日常subview的UITextView正确绘制大纲文本,直到文本换行.即使文本用户输入被包装,我绘制的轮廓文本也没有.这是我对该drawRect方法的实现:https://gist.github.com/4498988.在第29行,我使用char包装:
CTLineBreakMode linebreakmode = kCTLineBreakByCharWrapping;
Run Code Online (Sandbox Code Playgroud)
我已经尝试过wordwrapping选项(这也是默认选项)没有用.
我的问题是:如何将我绘制的文本正确包装,以便它显示为键入文本的大纲?
我有一个UITextView被解析并在键入某些字符时更改其属性.文本不会更改,只会更改描述文本格式的属性.
如果我解析每个字符条目,我基本上抓住它text,创建一个具有正确格式的属性字符串,并将attributedTexttextview 的属性设置为我的新属性字符串.这完全打破了自动更正,双倍空格快捷方式和拼写检查.
如果我只在键入某些特殊字符时进行解析,这会更好一点,但是我会得到奇怪的错误,比如每个句子的第二个单词都是大写的.
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
if (text.length == 0) {
return YES;
}
unichar firstCharacterInText = [text characterAtIndex:0];
if (/* special character */) {
[self processTextView];
}
}
- (void) processTextView {
NSString *text = self.text;
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text];
[attributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:kFontRegular size:12.0f] range:NSMakeRange(0, text.length)];
[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor textColor] range:NSMakeRange(0, text.length)];
// set other properties
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:有没有办法改变文本视图的文本属性而不重置textview的attributedText属性并打破所有这些方便的功能UITextView?
我有一个自定义的UIView,它通过CoreText绘制一个NSString:
- (NSMutableAttributedString *)getAttributedString : (NSString *)displayText {
string = [[NSMutableAttributedString alloc]
initWithString:displayText];
helvetica = CTFontCreateWithName(CFSTR("Helvetica"), 20.0, NULL);
[string addAttribute:(id)kCTFontAttributeName
value:(__bridge id)helvetica
range:NSMakeRange(0, [string length])];
return string;
}
- (void)drawRect:(CGRect)rect
{
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(
(__bridge CFAttributedStringRef)string);
// left column form
leftColumnPath = CGPathCreateMutable();
CGPathAddRect(leftColumnPath, NULL,
CGRectMake(0, 0,
self.bounds.size.width,
self.bounds.size.height));
// left column frame
textleftFrame = CTFramesetterCreateFrame(framesetter,
CFRangeMake(0, 0),
leftColumnPath, NULL);
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// right column form
rightColumnPath = CGPathCreateMutable();
CGPathAddRect(rightColumnPath, NULL,
CGRectMake(self.bounds.size.width/2.0, 0,
self.bounds.size.width/2.0,
self.bounds.size.height));
NSInteger …Run Code Online (Sandbox Code Playgroud) 使用NSAttributedString,我们可以更改字符串等的颜色.是否可以在字符串中倾斜特定字符.例如

答案将不胜感激.
我找到了一个不符合标准的解决方案.如果有人纠正了有用的代码
- (void)drawRect:(CGRect)rect {
CTFontRef sysUIFont = CTFontCreateUIFontForLanguage(kCTFontSystemFontType,
14.0, NULL);
// blue
CGColorRef color = [UIColor blueColor].CGColor;
// single underline
//NSNumber *underline = [NSNumber numberWithInt:kCTUnderlineStyleSingle];
NSDictionary *attributesDict = [NSDictionary dictionaryWithObjectsAndKeys:
(__bridge id)sysUIFont, (id)kCTFontAttributeName,
color, (id)kCTForegroundColorAttributeName, nil];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
CGContextTranslateCTM(context, 0, self.bounds.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
for (int i =0 ; i < 4; i++)
{
NSString *letter =[@"TEXT" substringWithRange:NSMakeRange(i, 1)];
NSAttributedString *stringToDraw = [[NSAttributedString alloc] initWithString:letter attributes:attributesDict];
// CGSize letterSize =[letter sizeWithAttributes:@{NSFontAttributeName:self.font}];
// draw
CTLineRef …Run Code Online (Sandbox Code Playgroud) 我想绘制一个段落(所以我猜使用CTFrameDraw或ctlinedraw)但我还需要截断文本,如果它不适合定义的区域(rect).通常我们通过附加省略号来修剪最后一行(即字符'...')如何做到这一点?如何使用像'... [+]这样的特殊字符来做到这一点
另外,我想知道如何为第一行指定缩进(以像素为单位)以及是否可以定义自定义linespacing
并且要完成,我需要知道完全适合整个段落的确切最终矩形(它可能低于定义的区域)
core-text ×10
ios ×9
objective-c ×5
iphone ×4
cocoa-touch ×2
android ×1
fonts ×1
linker ×1
nsstring ×1
uikit ×1
uitextview ×1
xcode ×1