Swift 常用 UI 组件开发指南
1. CG Color 与 UI 组件颜色设置
在 Swift 中,可以访问 Core Graphics 进行分层、变换或着色操作。对于 UI 按钮等组件,若要设置边框颜色,由于涉及核心图形操作,需使用 CGColor 而非 UIColor 。可以通过 CGColor 图形初始化或把 UIColor 转换为 CGColor 来实现。
以下是一个设置按钮样式的示例代码:
let bookLabelButton:UIButton = {
let button = UIButton()
button.translatesAutoresizingMaskIntoConstraints = false
button.contentEdgeInsets = UIEdgeInsets(top: 5, left: 5, bottom: 0, right: 0)
button.contentHorizontalAlignment = .center
button.contentVerticalAlignment = .center
button.setTitleColor(.white, for: .normal)
button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 16)
button.clipsToBounds = true
超级会员免费看
订阅专栏 解锁全文
1125

被折叠的 条评论
为什么被折叠?



