UISearchBar에 둥근 모서리를 왼쪽 상단과 오른쪽 상단 모서리에 추가하려고합니다.UISearchBar에서 마스크 작업을 마친 이유
그러나 마스크 레이어는 UISearchBar에서 작동하지 않습니다. 아무리 설정해도 문제가 없습니다.
여기에 내 코드
// UIView* bar = [searchBar_.subviews objectAtIndex:0]; // try to add mask to background view but also failed
UIView* bar = searchBar_;
CGRect toolbarBounds = bar.bounds;
CAShapeLayer *maskLayer = [CAShapeLayer layer];
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect: toolbarBounds
byRoundingCorners:UIRectCornerTopLeft
cornerRadii:CGSizeMake(5.0f, 5.0f)];
[maskLayer setPath:[path CGPath]];
[maskLayer setFillColor:[[UIColor greenColor] CGColor]];
bar.layer.masksToBounds = YES;
bar.layer.mask = maskLayer;
나는 또한 "클립 파단을"시도했다, 그러나 중 하나가 작동하지 않습니다.
그런 다음 더 많은 것을 시도하고 배경보기 (하위보기 0)를 숨겨 둡니다. 깜짝 놀라게하기 위해, 그것은 아직도 눈에 보인다.
UISearchBar에 어떤 마법이 있습니까? 마스크가 UIToolbar에서 작동합니다.
'view.layer.cornerRadius'를 사용해 보셨나요? –