Search This Blog

Saturday, October 16, 2010

Saturday, September 18, 2010

Compute needed height for fixed width of NSAttributedString



this function can helps us to determines the frame sizeneeded for a string range of an NSAttributedString in iphone/Ipad SDK for a given Width :

 it can be used for a dynamic height of UITableView Cells


- (CGSize)frameSizeForAttributedString:(NSAttributedString *)attributedString
{
    CTTypesetterRef typesetter = CTTypesetterCreateWithAttributedString((CFAttributedStringRef)attributedString);
    CGFloat width = YOUR_FIXED_WIDTH;
   
    CFIndex offset = 0, length;
    CGFloat y = 0;
    do {
        length = CTTypesetterSuggestLineBreak(typesetter, offset, width);
        CTLineRef line = CTTypesetterCreateLine(typesetter, CFRangeMake(offset, length));
       
        CGFloat ascent, descent, leading;
        CTLineGetTypographicBounds(line, &ascent, &descent, &leading);
       
        CFRelease(line);
       
        offset += length;
        y += ascent + descent + leading;
    } while (offset < [attributedString length]);
   
    CFRelease(typesetter);
   
    return CGSizeMake(width, ceil(y));
}

Friday, September 17, 2010

J2EE,Spring,Java technologies

Iphone/Ipad Development

After i saw that iphone and ipad applications dev is a wonderfull world , i like share my modest experience with my friends and people interested by this domain