I am creating a watermark to overlay on top of the image. Image can be expanded, enlarged, etc.
I created a watermark view class that, when sized, overlays a text label that is as large as within the borders. This works great and matches image sizes, etc.
Now I want to rotate the label. As soon as I apply the conversion, the text in the label is cut off. I guess I'm close, but I'm doing something stupid because I'm new to this. Any ideas?
Here is my class:
@interface WatermarkView () - (CGFloat)biggestBoldFontForString:(NSString*)text inRect:(CGRect)rect; @end @implementation WatermarkView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // create a label that will display the watermark mainLabel = [[UILabel alloc] initWithFrame:frame]; mainLabel.alpha = 0.35; mainLabel.backgroundColor = [UIColor clearColor]; mainLabel.text = @"watermark"; mainLabel.font = [UIFont boldSystemFontOfSize:[self biggestBoldFontForString:mainLabel.text inRect:mainLabel.frame]]; mainLabel.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; // rotate label to a random slanted angle mainLabel.transform = CGAffineTransformMakeRotation(RANDOM_FLOAT(-M_PI/5, -M_PI/6)); [self addSubview:mainLabel]; } return self; } - (void)dealloc { [mainLabel release]; [super dealloc]; } - (CGFloat)biggestBoldFontForString:(NSString*)text inRect:(CGRect)rect { CGFloat actualFontSize = 200; [text sizeWithFont:[UIFont boldSystemFontOfSize:200] minFontSize:1 actualFontSize:&actualFontSize forWidth:rect.size.width lineBreakMode:0]; return actualFontSize; } - (void)layoutSubviews { [super layoutSubviews]; mainLabel.font = [UIFont boldSystemFontOfSize:[self biggestBoldFontForString:mainLabel.text inRect:self.frame]]; } @end
source share