我目前正在使用属性addMessageLabel.layer.cornerRadius = 5.0f;
查看UILabel在安装了iOS 7.0的设备上,它有圆角。在安装了iOS 7.1的设备上,它没有圆角。
这只是iOS 7.1的错误吗?
答案 0 :(得分:458)
将属性clipsToBounds
设置为true
addMessageLabel.clipsToBounds = true
答案 1 :(得分:63)
我认为设置圆角半径的最佳方法是:
并确保"剪辑子视图"检查:
检查"剪辑子视图"等于代码addMessageLabel.clipsToBounds = YES;
。
答案 2 :(得分:22)
添加以下两行并检查它。
[[addMessageLabel layer] setCornerRadius:5.0f];
[[addMessageLabel layer] setMasksToBounds:YES];
OR
[addMessageLabel setClipsToBounds:YES];
答案 3 :(得分:4)
我的问题有点不同。
我做了做btn.clipsToBounds = true
我没有设置:
btn.layer.cornerRadius = 20
因为我有不同的屏幕尺寸。相反,我跟着this回答并做了:
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
}
答案 4 :(得分:3)
我尝试了下面的一个,我得到了一个成功的输出。
<ViewFlipper
android:id="@+id/myViewFlipper"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include android:id="@+id/firstLayout" layout="@layout/firstlayout"/>
<include android:id="@+id/secondLayout" layout="@layout/secondlayout"/>
<include android:id="@+id/thirdLayout" layout="@layout/thirdlayout" />`
</ViewFlipper>
还有其他东西阻止了你吗?
答案 5 :(得分:0)
//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
}
答案 6 :(得分:0)
yourlabelname.layer.cornerRadius = yourlabelname.frame.size.width/2;
[yourlabelname setClipsToBounds:YES];
确保使用适当的部署目标进行检查。
答案 7 :(得分:0)