1
나는 내 라벨에 쓰여진 텍스트가 사용자에게 보여 지도록 내 레이블 (동일한 이미지)의 이미지를 원한다. 프로그래밍 방식으로 ... 누군가 나를 안내 할 수 있다면 좋을 것입니다. 고마워요.레이블의 배경에 이미지를 프로그램 적으로 설정하기
나는 내 라벨에 쓰여진 텍스트가 사용자에게 보여 지도록 내 레이블 (동일한 이미지)의 이미지를 원한다. 프로그래밍 방식으로 ... 누군가 나를 안내 할 수 있다면 좋을 것입니다. 고마워요.레이블의 배경에 이미지를 프로그램 적으로 설정하기
가장 간단한 방법은 UIImageView를 UILabel 뒤에 레이어하는 것입니다. 좀 더 강력하게 만들고 싶다면 이미지 배경을 설정하는 메서드 나 속성을 제공하는 UILabel 하위 클래스를 만들어 이미지 자체를 추가 할 수 있습니다.
CGPoint labelPos = CGPointMake(123, 234);
UIImage *theImage = [UIImage imageNamed:@"button_bg.png"];
UIImageView *theImageView = [[UIImageView alloc] initWithImage:theImage];
theImageView.frame = CGRectMake(labelPos.x, labelPos.y, theImage.size.width, theImage.size.height);
UILabel *theLabel = [[UILabel alloc] initWithFrame:CGRectMake(labelPos.x, labelPos.y, 100, 50)];
theLabel.backgroundColor = [UIColor clearColor];
// ...label config...
[self.view addSubview:theImageView];
[self.view addSubview:theLabel];
[theImageView release];
[theLabel release];