Problem:
UITextView
and added a subview v1.Error:
It throws the following error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews.
Attempts Made:
layoutSubviews
and yet i get the same errorObjective
Question:
Thanks to @mackworth for the suggestion which led to the solution
For completeness I am answering it.
Overview:
There seems to be some trouble adding subview on UITextView
and then using Autolayout.
Solution:
So the solution is to create the HazeView as a subview to the parent view of UITextView
.
Steps:
UITextView
UITextView
and HazeView
as subview to the same parent viewHazeView
at the bottom of the UITextView
[UIColor clearColor]
HazeView
UIView
and put the UITextView
and HazeView
inside that so that it can be reusableCreating HazeView:
self.hazeView.backgroundColor = [UIColor clearColor];
HazeView
is a subclass of UIView
- (void)drawRect:(CGRect)rect
{
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = UIGraphicsGetCurrentContext();
UIColor *color1 = [UIColor colorWithRed:1.0 green:1.0
blue:1.0 alpha:0.25];
UIColor *color2 = [UIColor colorWithRed:1.0 green:1.0
blue:1.0 alpha:0.5];
UIColor *color3 = [UIColor colorWithRed:1.0 green:1.0
blue:1.0 alpha:0.75];
NSArray *gradientColors = @[(id) color1.CGColor,
(id) color2.CGColor,
(id) color3.CGColor];
CGFloat gradientLocations[] = {0, 0.50, 1};
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef) gradientColors, gradientLocations);
CGPoint startPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect));
CGPoint endPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMaxY(rect));
CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
CGGradientRelease(gradient);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With