我正在創建一個水印來重疊在圖像視圖的頂部。圖像可以平移,縮放等。UILabel文本旋轉時會截斷。怎麼修?
我已經創建了一個水印視圖類,它的大小和覆蓋範圍一樣大的文本標籤會適合邊界。這個工程很好,尺寸適當,因爲圖像的大小等。
現在我想旋轉標籤。只要應用轉換,標籤中的文本就會截斷。我認爲我很接近,但我做了一些愚蠢的事情,因爲我是新手。有任何想法嗎?
這裏是我的類:
@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
你發現問題了嗎? – newenglander
你說'現在我想旋轉標籤',這是用戶何時旋轉設備? – Patrick