【发布时间】:2020-10-17 21:17:36
【问题描述】:
我正在尝试快速实现以下按钮。
这是我目前所拥有的
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)
如何使代码看起来像我展示的设计?
【问题讨论】:
-
看这里的答案,这可能会有所帮助:stackoverflow.com/questions/38874517/…
-
请将您的cornerRadius更新为按钮层的24,因为按钮的高度是48