2016-08-25 4 views
1

UIView로 일부 원형 하위 뷰가있는 tableview를 만들고 싶습니다. UIView의 layer.cornerRadius 및 clipsToBounds를 설정합니다. 그러나 일부 의견은 반올림되지 않습니다. 누가이 문제를 해결하거나 조언을 해 줄 수 있습니까? UITableViewCell의 하위 뷰는 둥글 수 없습니다.

내 코드 :

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    static NSString * settCellID = @"settingCellID"; 
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:settCellID]; 
    if (!cell) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:settCellID]; 

     UIView * view = [[UIView alloc] initWithFrame:CGRectMake(100, 10, 20, 20)]; 
     view.layer.cornerRadius = 10; 
     view.clipsToBounds = 1; 
     view.layer.rasterizationScale = [UIScreen mainScreen].scale; 
     view.layer.shouldRasterize = 1; 
     view.backgroundColor = [UIColor blueColor]; 
     [cell.contentView addSubview:view]; 
    } 
    return cell; 
} 

결과 : 당신이 원하는 경우,이 clipsToBound 내부

enter image description here

+0

장치 또는 시뮬레이터에서 발생합니까? – beyowulf

+0

행 높이로 반환하는 값은 무엇입니까? 이 둥근 뷰의 높이보다 크다. –

+0

이 시뮬레이터에서 발생합니까? 시뮬레이터의 고장 가능성이 있습니다. 시뮬레이터 스케일을 100 %로 설정하십시오 (메뉴 : 윈도우 -> 스케일 -> 100 %). – Jeyamahesan

답변

1

시도해 볼 것 사용자 지정 셀 클래스를 만들고 스토리 보드를 사용하여 프로그래밍 방식으로 만들지 않은보기를 만듭니다. 사용자 정의 셀 클래스에서 뷰의 속성을 설정합니다. 위의 코드를 구현하지만 약간의 변경 사항은 여기에서 언급했습니다.

static NSString * settCellID = @"settingCellID"; 
'CustomClassName' * cell = (CustomClassName*)[tableView dequeueReusableCellWithIdentifier:settCellID]; 
cell.viewPropertyName.layer.cornerRadius = 10; 
cell.viewPropertyName.clipsToBounds = YES; 
cell.viewPropertyName.maskToBounds =YES; 
cell.viewPropertyName.backgroundColor = [UIColor blueColor]; 
+0

당신의 도움에 감사드립니다, 나는 당신의 제안에 사용 된 문제를 해결합니다. 나는 원형보기를 만드는 우리의 방법에 대한 차이점을 모른다. 자신의 길을 사용했던 원근법은 갈등처럼 더 많이 만들었습니다. 네가 그걸 안다면 나 한테 말해줘. –

0

은 모서리 반경에 대한 YES = 그래서 당신은 YES 제공하거나 NO 및 maskToBound를 사용하려고한다 BOOL 인 그에 따라 clipsToBound를 사용하는 것보다 아래보기를 병합하는 것이 좋으며 여기서는 rasterizationScale 및 shouldRasterize가 유용하다고 생각하지 않습니다. 나는 이것이 당신을 도울 것을 희망합니다. 당신이있는 UITableViewCell 원한다면

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString * settCellID = @"settingCellID"; 
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:settCellID]; 
if (!cell) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:settCellID]; 

    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(100, 10, 20, 20)]; 
    view.layer.cornerRadius = 10; 
    view.clipsToBounds = YES; 
    view.maskToBounds =YES; 
    view.layer.rasterizationScale = [UIScreen mainScreen].scale; 
    view.layer.shouldRasterize = 1; 
    view.backgroundColor = [UIColor blueColor]; 
    [cell.contentView addSubview:view]; 
} 
return cell; 
} 

는 그리고 rasterizationScale 및 shouldRasterize는 "오프 스크린 렌더링 '을위한이 Link Click here

+0

rasterizationScale과 shouldRasterize는 "오프 스크린 렌더링"을위한 것이지만 라운드 뷰에는 영향을 미치지 않습니다. "view.clipsToBounds = YES"는 "view.layer.masksToBounds = 1"과 같습니다. 이미 CGContextRef와 UIBezierPath를 사용하여 UITableViewCell에서 둥근 뷰를 만들었지 만 실제 원형 뷰를 만들 수는 없습니다. –

+0

그리고 Storyboard에서 사용자 정의 셀을 만들고 사용자 정의 실행 시간 속성을 설정하십시오. 사용자 정의 런타임 특성을 사용하는 데 도움이 될 것입니다.이 링크를 선호합니다. http://stackoverflow.com/questions/12301256/is-it-possible-to -set-uiview-border-properties-from-interface-builder –

+0

도움 주셔서 감사합니다. 나는 이미 락의 방법으로이 문제를 해결했다. 사용자 지정 원형보기 만 사용하여이 문제를 해결할 수 있습니다. 그러나 나는 그들에 대한 차이점을 알지 못합니다. @ Kartik Singh Bhadoriya –

0

에 따라보다 모서리와 클립 파단 둥근하지만 라운드보기에는 영향을주지 않습니다. "view.clipsToBounds = YES"는 "view.layer.masksToBounds = 1"과 같습니다. 이미 CGContextRef와 UIBezierPath를 사용하여 UITableViewCell에서 둥근 뷰를 만들었지 만 실제 원형 뷰를 만들 수는 없습니다.

관련 문제