반응형
UI 레이블 layer.cornerRadius가 iOS 7.1에서 작동하지 않음
현재 속성이 있는 UI 레이블을 찾고 있습니다.addMessageLabel.layer.cornerRadius = 5.0f;
iOS 7.0이 설치된 장치에서는 모서리가 둥글게 처리됩니다.iOS 7.1이 설치된 장치에서는 모서리가 둥글지 않습니다.
이것은 단지 iOS 7.1의 버그입니까?
속성 설정clipsToBounds
정말로
addMessageLabel.clipsToBounds = true
코너 반경을 설정하는 가장 좋은 방법은 다음과 같습니다.
"Clip Subviews"가 선택되어 있는지 확인합니다.
"Clip Subviews" 확인은 코드와 동일합니다.addMessageLabel.clipsToBounds = YES;
.
다음을 시도합니다.
[[addMessageLabel layer] setCornerRadius:5.0f];
[[addMessageLabel layer] setMasksToBounds:YES];
//or
[addMessageLabel setClipsToBounds:YES];
스위프트
addMessageLable.layer.cornerRadius = 5.0
addMessageLable.layer.masksToBounds = true
//or
addMessageLable.layer.clipsToBounds = true
제 문제는 좀 달랐습니다.
내가 한 동안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
반응형
'sourcecode' 카테고리의 다른 글
스프링 부트 연속 빌드로 실행 (0) | 2023.06.28 |
---|---|
테이블 정의를 표시하기 위한 T-SQL 쿼리? (0) | 2023.06.28 |
오류: 기본 재배치로 풀링할 수 없습니다.단계별 변경사항이 있습니다. (0) | 2023.06.28 |
깃 풀 대 깃 베이스 (0) | 2023.06.28 |
views.py 을 여러 파일로 분할 (0) | 2023.06.28 |