Note that there are some explanatory texts on larger screens.

plurals
  1. POAuto-expanding a UIView and CGPath to fit Core Text
    primarykey
    data
    text
    <p>I've been searching all over stack to an answer for this, although there is a lot on the topic nothing quite seems to answer the question, at least not to me.</p> <p>I have a custom UIView of fixed size in storyboard (in a prototype cell). I subclassed UIView for it and over-wrote the drawRect Method. It basically puts together a formatted string, then I draw it like so:</p> <pre><code>// now for the actual drawing CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetShadowWithColor(context, CGSizeMake(0, 1), 0, [UIColor whiteColor].CGColor); CGMutablePathRef path = CGPathCreateMutable(); //1 CGPathAddRect(path, NULL, self.bounds ); // flip the coordinate system CGContextSetTextMatrix(context, CGAffineTransformIdentity); CGContextTranslateCTM(context, 0, self.bounds.size.height); CGContextScaleCTM(context, 1.0, -1.0); CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)stringToDraw); //3 CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), path, NULL); CTFrameDraw(frame, context); //4 </code></pre> <p>That's fine and works and if I make the default size big enough, it'll handle multiple lines of text.</p> <p>The CGPath uses all of the UIView, that's fine/desired.</p> <p>I want to keep the CGPath's width fixed, but I want the height to expand to accomodate an essentially unlimited amount of text, right now it just gets cut off (due to the path/view not being big enough to encompass it)</p> <p>I've tried playing with CTFramesetterSuggestFrameSizeWithConstraints to no avail. Can someone please help me develop some code that will achieve what I need to do?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload