최근에 XCode 프로젝트를 작업 할 때 배경색을 groupTableViewBackgroundColor로 설정했습니다.이 배경색은 아이폰에서 줄무늬가있는 배경을 만들어 잘 작동합니다. 이 배경은 UITableViews에서 사용 된 배경과 동일합니다.
iPad로 이식 할 때 UITableView는 이제 단색 회색을 가지며 groupTableViewBackgroundColor는 기본적으로 [UIColor clearColor]와 같습니다.
UITableView가 사용하는 색상을 잡는 것이 효과가 있다고 생각할 것입니다. 그것이 약간의 그라디언트 일 뿐이지 만 눈에 띄지는 않지만,보기를 바꿀 때주의해야합니다.
이 문제를 해결하려면 CAGradientLayer를 만들어 UIView에 적용한 다음로드해야합니다.
-(CAGradientLayer *)groupGradientColour {
CAGradientLayer *layer = [CAGradientLayer layer];
layer.colors = [NSArray arrayWithObjects:
(id)[[UIColor colorWithRed:(0xE2/255.0)
green:(0xE5/255.0)
blue:(0xE9/255.0)
alpha:1.0] CGColor],
(id)[[UIColor colorWithRed:(0xD0/255.0)
green:(0xD2/255.0)
blue:(0xD7/255.0)
alpha:1.0] CGColor],
nil];
layer.locations = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0f],
[NSNumber numberWithFloat:1.0f],
nil];
return layer;
}
다음의 viewDidLoad이 전화 : 일단 당신이 이것을하면
UIView *background = [[UIView alloc] init];
background.frame = CGRectMake(
0,
0,
[[UIScreen mainScreen] applicationFrame].size.width,
[[UIScreen mainScreen] applicationFrame].size.height);
CAGradientLayer *gradient = [self groupGradientColour];
gradient.frame = background.bounds;
[background.layer insertSublayer:gradient atIndex:0];
[self.view addView:background atIndex:0];
것은, 당신이해야합니다 첫째로, 당신은 아래 내가 사용하는 것입니다, 그라데이션을 에뮬레이트하는 함수를 작성해야 그라데이션은 UITableView와 같은 스타일입니다.
답변 해 주셔서 감사합니다. 나는 이것을 시도하고 알릴 것이다. – Sreeram
잘 작동합니다. insertSubview 의미하는 것 같아요 : atIndex보다는 addView : atIndex 비록? – edsko