UIColor.colorWithPatternImageを使用することでUILabelの背景に画像を設定できるのですが、Xcode6でビルドしてiOS8で動かすと画像がおかしくなります。
原因はわかっていないのですがラベルに日本語を設定した場合だけズレるようです。
下記を追加することで対応できます。
label.clipsToBounds = YES;
コード
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
{
UILabel *label = [[UILabel alloc] init];
label.text = @"koreha daijoubu";
label.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"test"]];
label.frame = CGRectMake(100.0, 100.0, 124.0, 21.0);
[self.view addSubview:label];
}
{
UILabel *label = [[UILabel alloc] init];
label.text = @"これはダメ";
label.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"test"]];
label.frame = CGRectMake(100.0, 100.0 + 100.0, 124.0, 21.0);
[self.view addSubview:label];
}
{
UILabel *label = [[UILabel alloc] init];
label.text = @"こうするとOK";
label.clipsToBounds = YES;
label.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"test"]];
label.frame = CGRectMake(100.0, 100.0 + 200.0, 124.0, 21.0);
[self.view addSubview:label];
}
}