나는 이것을 거의 쉽게 할 수 없다. 나는 나의 기술 지원 요청 중 하나를 최근 devut 계정에 사용하여 UITableView 섹션의 배경과 테두리를 변경하는 것에 대해 최근에 물었다. 사과 엔지니어는이 작업이 실제로는 쉬운 일이 아니라고 말했고, 수행 한 경우에도 성능에 영향을 미칠 수 있다고 말했습니다. 그는 또한 cocoawithlove 저를 지적하고 편집 uitableviews에 대한 기사 :
http://cocoawithlove.com/2009/08/adding-shadow-effects-to-uitableview.html
정말, 자신의 헤더를 만드는 것은 그 많은 노력이 아니다. 그것은 주석, 그래서 바로 작동하지 않을 수 있습니다 - - 아래는 내 프로젝트 중 하나에서 철수 일부 코드는하지만 당신은 아이디어를 얻을 수 있습니다 :
- (CAGradientLayer *) greyGradient {
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.startPoint = CGPointMake(0.5, 0.0);
gradient.endPoint = CGPointMake(0.5, 1.0);
UIColor *color1 = [UIColor colorWithRed:255.0f/255.0f green:255.0f/255.0f blue:255.0f/255.0f alpha:1.0];
UIColor *color2 = [UIColor colorWithRed:240.0f/255.0f green:240.0f/255.0f blue:240.0f/255.0f alpha:1.0];
[gradient setColors:[NSArray arrayWithObjects:(id)color1.CGColor, (id)color2.CGColor, nil]];
return gradient;
}
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
CGFloat width = CGRectGetWidth(tableView.bounds);
CGFloat height = [self tableView:tableView heightForHeaderInSection:section];
UIView *container = [[[UIView alloc] initWithFrame:CGRectMake(0,0,width,height)] autorelease];
container.layer.borderColor = [UIColor grayColor].CGColor;
container.layer.borderWidth = 1.0f;
CAGradientLayer *gradient = [self greyGradient];
gradient.frame = container.bounds;
[container.layer addSublayer:gradient];
UILabel *headerLabel = [[[UILabel alloc] initWithFrame:CGRectMake(12,0,width,height)] autorelease];
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.font= [UIFont boldSystemFontOfSize:19.0f];
headerLabel.shadowOffset = CGSizeMake(1, 1);
headerLabel.textColor = [UIColor whiteColor];
headerLabel.shadowColor = [UIColor darkGrayColor];
NSString *title = [self tableView:tableView titleForHeaderInSection:section];
headerLabel.text = title;
return container;
}
확인
#import <QuartzCore/QuartzCore.h>
에 작성자 방법 ... 표준 헤더의 모양을 모방하지 않아도됩니다. 하지만 약간의 시행 착오로 표준을 모방 한 다음 색을 약간 바꿀 수 있다고 확신합니다.
텍스트에 뭔가 빠져있는 것 같습니다. #import what? 아마도 핵심 애니메이션 물건일까요? – Thorsten
오, 네, CAGradientLayer를 사용하기위한 QuartzCore였습니다 - 게시에 추가하겠습니다. 감사합니다 – bandejapaisa
또한 [container addSubview : headerLabel]이 누락되었습니다. 다음과 같이하면 더 좋습니다. \t CGFloat width = tableView.bounds.size.width; \t CGFloat height = [self tableView : tableView heightForHeaderInSection : section]; UIView * container = [[UIView alloc] initWithFrame : CGRectMake (0,0, width, height)]; –