programing

UIlabel layer.cornerRadius가 iOS 7.1에서 작동하지 않습니다

new-time 2020. 5. 18. 21:48
반응형

UIlabel layer.cornerRadius가 iOS 7.1에서 작동하지 않습니다


현재

addMessageLabel.layer.cornerRadius = 5.0f;

iOS 7.0이 설치된 장치에서 모서리가 둥근 UILabel 속성을보고 있습니다. iOS 7.1이 설치된 기기에는 둥근 모서리가 없습니다.이것은 iOS 7.1의 버그입니까?


속성

clipsToBounds

을 true로 설정

addMessageLabel.clipsToBounds = true

코너 반경을 설정하는 가장 좋은 방법은 다음과 같습니다.

여기에 이미지 설명을 입력하십시오

"클립 서브 뷰"가 체크되어 있는지 확인하십시오 :

여기에 이미지 설명을 입력하십시오

"Clip Subviews"를 확인하는 것은 코드와 같습니다

addMessageLabel.clipsToBounds = YES;

.


아래 두 줄을 추가하고 확인하십시오.

[[addMessageLabel layer] setCornerRadius:5.0f];
[[addMessageLabel layer] setMasksToBounds:YES];

또는

[addMessageLabel setClipsToBounds:YES];

내 문제는 조금 달랐습니다. 나는 동안

btn.clipsToBounds = true

나는 설정하지 않았다 :

btn.layer.cornerRadius = 20

화면 크기가 다르기 때문입니다. 대신 나는

대답을 따르고 했다 :

override func layoutSubviews() {
    seeMoreButton.layer.cornerRadius = seeMoreButton.bounds.size.height / 2
}

추가하는 것을 잊었 기 때문에 작동하지 않았습니다

super.layoutSubviews()

. 올바른 코드는 다음과 같습니다.

override func layoutSubviews() {
    super.layoutSubviews()
    seeMoreButton.layer.cornerRadius = seeMoreButton.bounds.size.height / 2
}

나는 아래의 것을 시도했고 성공적인 결과를 얻었다.

yourlabelname.layer.cornerRadius = 10.0f;
[yourlabelname setClipsToBounds:YES];

당신을 방해하는 다른 것이 있습니까?


 //works perfect in Swift 2.0 for a circular or round image          


@IBOutlet var theImage: UIImageView!
        override func viewDidLoad() {
            super.viewDidLoad()
    //Make sure the width and height are same
            self.theImage.layer.cornerRadius = self.theImage.frame.size.width / 2
            self.theImage.layer.borderWidth = 2.0
            self.theImage.layer.borderColor = UIColor.whiteColor().CGColor
            self.theImage.clipsToBounds = true

        }

yourlabelname.layer.cornerRadius = yourlabelname.frame.size.width/2;
[yourlabelname setClipsToBounds:YES];

적절한 배포 대상을 확인하고 있는지 확인하십시오.


UIView의 확장으로 다음 코드를 추가하십시오.

//// Story board Extra Feature for create border radius, border width and border Color
extension UIView {
    /// corner radius
    @IBInspectable var borderColor: UIColor? {
        set {
            layer.borderColor = newValue!.cgColor
        }
        get {
            if let color = layer.borderColor {
                return UIColor(cgColor: color)
            } else {
                return nil
            }
        }
    }
    @IBInspectable var borderWidth: CGFloat {
        set {
            layer.borderWidth = newValue
        }
        get {
            return layer.borderWidth
        }
    }
    @IBInspectable var cornerRadius: CGFloat {
        set {
            layer.cornerRadius = newValue
            clipsToBounds = newValue > 0
        }
        get {
            return layer.cornerRadius
        }
    }
}

그 후 인터페이스 빌더 자체에서 다음 속성을 얻습니다.!

여기에 이미지 설명을 입력하십시오

참고 URL :

https://stackoverflow.com/questions/22316836/uilabel-layer-cornerradius-not-working-in-ios-7-1

반응형