English 中文(简体)
CTFrameGet 可见StringRange () 返回 0
原标题:CTFrameGetVisibleStringRange() returns 0

我有一个代码, 这个代码在读取 NASATRT TRATITED String 时生成了一系列查看控制器。 在第一个周期后, 函数 CTFrameGetVeableStringRange () 返回 0, 即使有更多的文本要显示 。

- (void)buildFrames
{
/*here we do some setup - define the x & y offsets and create an empty frames array */
    float frameXOffset = 20; 
    float frameYOffset = 20;

    self.frames = [NSMutableArray array];

    //buildFrames continues by creating a path and a frame for the view s bounds (offset slightly so we have a margin).
    CGMutablePathRef path = CGPathCreateMutable(); 
    // create an insect rect for drawing
    CGRect textFrame = CGRectInset(self.bounds, frameXOffset, frameYOffset); 
    CGPathAddRect(path, NULL, textFrame );// add it to the path

    // Create a frame setter with my attributed String
    CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attributedString);

    //This section declares textPos, which will hold the current position in the text. 
    //It also declares columnIndex, which will count how many columns are already created.
    int textPos = 0; 
    int columnIndex = 0;

    while (textPos < [attributedString length]) { 
        //The while loop here runs until we ve reached the end of the text. Inside the loop we create a column bounds: colRect is a CGRect which depending on columnIndex holds the origin and size of the current column. Note that we are building columns continuously to the right (not across and then down).

        CGPoint colOffset = CGPointMake(frameXOffset , frameYOffset);
        CGRect columnRect = CGRectMake(0, 0 , textFrame.size.width, textFrame.size.height);

        CGMutablePathRef path = CGPathCreateMutable();
        CGPathAddRect(path, NULL, colRect);

        CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(textPos, 0), path, NULL);
        CFRange frameRange = CTFrameGetVisibleStringRange(frame); 

       // MY CUSTOM UIVIEW
        LSCTView* content = [[[LSCTView alloc] initWithFrame: CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)] autorelease];
        content.backgroundColor = [UIColor clearColor];
        content.frame = CGRectMake(colOffset.x, colOffset.y, columnRect.size.width, columnRect.size.height) ;

    /************* CREATE A NEW VIEW CONTROLLER WITH view=content *********************/

        textPos += frameRange.length;

        CFRelease(path);

        columnIndex++;
     }
}
问题回答

您是否更改了归属于 String 的对齐? 我有一个萨米问题, 发现有时当文本对齐被设置为 kCT 正义化TextAgrimination 时, 文本对齐会发生 。 它应该适合休息类型 。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签