는 다음과 같은 이미지를 살펴 보자 :UIButton 컨트롤에서 날카로운 사각형 모서리를 제거하는 방법?
당신은 가장자리가 날카로운 사각형이고 그들은 둥근 모서리 버튼에서 오는 볼 수 있듯이. 가장자리를 표시하지 않고 둥근 버튼 만 표시하려면 어떻게해야합니까?
UPDATE (솔루션) :
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.stopButton.bounds
byRoundingCorners:UIRectCornerAllCorners
cornerRadii:CGSizeMake(12.0, 12.0)];
// Create the shape layer and set its path
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = self.stopButton.bounds;
maskLayer.path = maskPath.CGPath;
// Set the newly created shape layer as the mask for the image view's layer
self.stopButton.layer.mask = maskLayer;
새로운 문제 :이 코드는 나에게 startButtonRound.layer에 오류가 있습니다
나는 둥근 모서리를 달성하기 위해 다음 코드를 사용했다. cornerRadius 라인.
UIButton *roundStartButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
roundStartButton.frame = CGRectMake(10, 10, 100, 20);
[roundStartButton setBackgroundImage:[UIImage imageNamed:@"green_gradient.jpg"] forState:UIControlStateNormal];
roundStartButton.layer.cornerRadius = 12.0;
UIBarButtonItem *startButton = [[UIBarButtonItem alloc] initWithCustomView:roundStartButton];
[버튼 레이어] setCornerRadius : 5.0f]를 시도했습니다. 버튼에 아무런 영향을주지 않았습니다. – azamsharp
레이어를 둥근 모서리로 잘라내려면 MasksToBounds를 yes로 설정해야 할 수도 있습니다. –
cornerRadius가 작동하도록 UIButton을 IBOutlet으로 선언해야합니까? 업데이트 된 원래 게시물을 참조하십시오. – azamsharp