Hi I'm working with the new TextKit
API for iOS7 and I'm trying to produce a UITextView
with an irregular shape. So far I have in a view controller:
-(void) loadView
{
self.view = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,548)];
NSTextStorage *textStorage = [[NSTextStorage alloc] init];
NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
[textStorage addLayoutManager: layoutManager];
BaseTextContainer *textContainer = [[BaseTextContainer alloc] initWithSize:CGSizeMake(100, 100)];
[layoutManager addTextContainer: textContainer];
BaseTextView *textView = [[BaseTextView alloc] initWithFrame:CGRectMake(110,124, 100, 100) textContainer:textContainer];
textView.backgroundColor = [UIColor blueColor];
textView.editable = YES;
[self.view addSubview:textView];
}
Then in my subclassed NSTextContainer
, I want to have a mutablePath
drawn as the shape of the text container, but not sure how to accomplish this. I have:
- (BOOL) isSimpleRectangularTextContainer
{
return NO;
}
- (void) drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
{
NSLog(@"TEST");
CGContextRef context = ctx;
CGSize layerSize = layer.frame.size;
CGAffineTransform transform = CGAffineTransformMakeScale(layerSize.width / self.initialSize.width, layerSize.height / self.initialSize.height);
CGMutablePathRef newGraphicMutablePath = CGPathCreateMutableCopyByTransformingPath(self.mutablePath, &transform);
CGContextAddPath(context, newGraphicMutablePath);
CGPathRelease(newGraphicMutablePath);
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
CGContextDrawPath(context, kCGPathFill);
}
Just a bit confused about how to get this to work. I cannot find an example anywhere of an NSTextContainer
with an irregular shape.