[英]layer.cornerRadius not working in conjunction with NSLayoutConstraints (swift 3)
[英]UIlabel layer.cornerRadius not working in iOS 7.1
我目前正在查看具有属性addMessageLabel.layer.cornerRadius = 5.0f;
的 UILabel addMessageLabel.layer.cornerRadius = 5.0f;
在安装了 iOS 7.0 的设备上,它有圆角。 在安装了 iOS 7.1 的设备上,它没有圆角。
这只是 iOS 7.1 的一个错误吗?
将属性clipsToBounds
设置为 true
addMessageLabel.clipsToBounds = true
我认为设置拐角半径的最佳方法是:
并确保选中“剪辑子视图”:
检查“剪辑子视图”等于代码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
}
}
}
之后,您将在界面构建器本身中获得以下属性。!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.