ios - 快速创建按钮
问题描述
我正在尝试快速实现以下按钮。
这是我到目前为止所拥有的
let startBtn = UIButton(frame: CGRect(x: (self.view.frame.width - 319)/2, y: progressView.frame.maxY + 10, width: 319, height: 48))
startBtn.backgroundColor = UIColor(red: 0.00, green: 0.83, blue: 0.69, alpha: 1.00);
startBtn.layer.cornerRadius = 40
startBtn.setTitleColor(UIColor.white, for: .normal)
startBtn.titleLabel?.textAlignment = .center
startBtn.contentVerticalAlignment = .center
startBtn.titleLabel?.font = UIFont(name: "CeraPro-Medium", size: 17);
if (self.courseProgress != nil && self.courseProgress >= 0) {
startBtn.setTitle("Resume Course", for: .normal)
} else {
if (hasPurchased) {
startBtn.setTitle("Start Course", for: .normal)
} else {
if let price = self.data.price {
startBtn.setTitle("Buy this course for $\(price)", for: .normal)
}
}
}
startBtn.addTarget(self, action:#selector(self.goToCourse(sender:)), for: .touchUpInside)
headerView.addSubview(startBtn)
我怎样才能使该代码看起来像我展示的设计?
解决方案
圆角半径问题。
您可能应该通过以下方式设置角半径:
startBtn.layer.cornerRadius = startBtn.bounds.height / 2
它允许正确地圆角按钮
推荐阅读
- mysql - 续集错误:包括意外。元素必须是模型、关联或对象
- node.js - 我们可以使用客户端 IP 地址在 node.js 上发出 http 请求吗?
- angular - Dotnet 核心 3.1 返回 401 和状态文本 OK
- python - Python / Matplotlib:带有contourf的颜色条不尊重自定义cmap的刻度标签
- javascript - 跨度标签内的可编辑文本并将光标放在末尾(Javascript)
- bash - 使用 Makefile 修剪读取输入
- sql-server - 从 fn_dblog 更新事务中获取主键
- airflow - 触发 Airflow DAG 时提交配置:它有什么作用?
- amazon-s3 - 了解 Active Storage Direct 上传错误:`存储“File_1.jpeg”时出错。状态:0`
- python - spaCy 空白 NER 模型拟合不足,即使在大型数据集上进行训练