UITableViewCell 하위 클래스를 사용하고 사용자 지정 반경이있는 사용자 지정보기를 contentView에 추가하는 것이 좋습니다.
여기 내 간단한 구현입니다.
#import "TableViewCell.h"
#import "RoundedView.h"
@implementation TableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
RoundedView *roundedView = [[RoundedView alloc] initWithFrame:CGRectInset(self.contentView.bounds, 2, 2)];
[self.contentView addSubview:roundedView];
}
return self;
}
@end
그리고 반올림하여 필요한 모서리에 둥근 모서리를 설정합니다.
#import "RoundedView.h"
@implementation RoundedView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
}
return self;
}
- (void)drawRect:(CGRect)rect{
CGContextRef context = UIGraphicsGetCurrentContext();
UIBezierPath *bp = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerTopRight | UIRectCornerBottomLeft cornerRadii:CGSizeMake(10, 10)];
CGContextAddPath(context, bp.CGPath);
CGContextClip(context);
[[UIColor brownColor] setFill];
UIRectFill(rect);
}
@end
그리고 cellForRowAtIndexPath 내부
:,보기 만 initWithStyle 내부의 셀에 추가되므로
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CELL"];
if(!cell){
cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CELL"];
}
return cell;
}
참고 reuseIdentifier :있어서, 상기 뷰는 단지 새로운 셀이 할당되면 그리는 것이다. 대부분의 경우 UITableView는 셀을 대기열에서 제외하므로 몇 시간 만 그려집니다. 이 성능이 가장 좋은 것입니다 왜
그리고 최종 결과는 다음과 같습니다는
당신은 설명 할 수 있습니까? –
셀이 존재하지 않으면 셀에 대한 사용자 정의 수정을 실행합니다. 이것은 ** 선언 된 새 셀마다 한 번만 발생합니다. if 문 외부에서 수행하는 것과 반대되는 작업입니다. 사용자 정의 변경 사항이 표시되는 각 셀에 대해 더 많이 실행됩니다. – royherma
그래서 셀을 재사용하고 있기 때문에 최초로 셀을 변경했을 때만 호출 할 것입니다. –