My application is setup as so.
Custom UIView inside a ScrollView.
The custom UIView is getting text generated on top of it with this code.
CoreDavening.m draw function
attStorage = [[NSTextStorage alloc]initWithAttributedString:string];
textContainer = [[NSTextContainer alloc]
initWithSize:CGSizeMake(self.frame.size.width, FLT_MAX)];
layoutManager = [[NSLayoutManager alloc]init];
[layoutManager addTextContainer:textContainer];
[attStorage addLayoutManager:layoutManager];
NSRange glyphRange = [layoutManager
glyphRangeForTextContainer:textContainer];
[layoutManager drawGlyphsForGlyphRange: glyphRange atPoint: rect.origin];
In my ViewController.m I'm creating the view like so.
CoreDavening *davenView = [[CoreDavening alloc]initWithFrame:CGRectMake(0, 0,self.view.frame.size.width, [coreDavening heightForStringDrawing])];
davenView.backgroundColor = [UIColor whiteColor];
davenView.layer.borderColor = [[UIColor whiteColor]CGColor];
scrollView.backgroundColor = [UIColor whiteColor];
[scrollView addSubview:davenView];
self.scrollView.contentSize = davenView.frame.size;
Im trying to find a way to 1) change the font size (just size) 2) have the scrollView and CustomView resize appropriately.
How can this be done?
EDIT 1: Im creating the custom view in my viewController like this.
CoreDavening *coreDavening = [[CoreDavening alloc]init];
davenView = [[CoreDavening alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, [coreDavening heightForStringDrawing ])];
and updating/refreshing the custom view like this.
It get triggered when the slider I have set up changes value.
- (IBAction)sliderChanged:(id)sender {
NSUserDefaults *prefs= [NSUserDefaults standardUserDefaults];
[prefs setInteger:(long)self.Slider.value forKey:@"fontSize"];
[prefs synchronize];
[davenView setNeedsLayout];
}
My custom view controller has the font set up like.
THIS IS IN THE DRAW FUNCTION
attStorage = [[NSTextStorage alloc]initWithAttributedString:string];
[attStorage addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:(long)[prefs integerForKey:@"fontSize"]] range:NSMakeRange(0, attStorage.length)];
textContainer = [[NSTextContainer alloc]
initWithSize:CGSizeMake(self.frame.size.width, FLT_MAX)];
layoutManager = [[NSLayoutManager alloc]init];
[layoutManager addTextContainer:textContainer];
[attStorage addLayoutManager:layoutManager];
NSRange glyphRange = [layoutManager
glyphRangeForTextContainer:textContainer];
[layoutManager drawGlyphsForGlyphRange: glyphRange atPoint: rect.origin];