iOS 角标(Badge)像 UILabel 故障

标签 ios iphone xcode swift

请帮我做一个像 UILabel 这样的简单角标(Badge)。

我的代码是:

let badgeLabel = UILabel(frame: CGRectMake(0, 0, 25, 25))
badgeLabel.backgroundColor = UIColor.clearColor()
badgeLabel.layer.backgroundColor = UIColor.redColor().CGColor
badgeLabel.layer.cornerRadius = 25/2
badgeLabel.layer.borderWidth = 3.0
badgeLabel.layer.borderColor = UIColor.whiteColor().CGColor

结果我得到了一个 UILabel,在白色边框上有一个红色的小笔划:

enter image description here

enter image description here

最佳答案

试试这个。

让badgeLabel = UILabel(frame: CGRectMake(0, 0, 25, 25)) badgeLabel.backgroundColor = UIColor.redColor() badgeLabel.layer.backgroundColor = UIColor.clearColor().CGColor 角标(Badge)标签.layer.cornerRadius = 25/2 badgeLabel.layer.borderWidth = 3.0 badgeLabel.layer.borderColor = UIColor.whiteColor().CGColor

关于iOS 角标(Badge)像 UILabel 故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28171886/

相关文章:

objective-c - For 循环会按照此模式在索引 : 0, 1 然后 1,2 然后 2,3 然后 3,4 处给我对象,直到数组计数?

iphone - 退出应用后重置亮度

ios - 如何以分组样式设置 UITableView 中单元格的宽度

ios - UICollection View 永远不会加载

ios - tableviewcell 中的图像不会立即出现

ios - Swift: fatal error :在初始化 UIlabel 值时展开可选值时意外发现 nil

ios - Xcode 编译错误

Xcode 7 错误代码“无法转换值类型([AnyObject]

ios - CoreData 完成后 Swift iOS 9 UITableView 重新加载数据

iphone - 设置状态栏隐藏后不旋转