我想在锁定屏幕上创建一个带有圆形框架的按钮,例如默认的iOS框架,您可以输入密码来解锁iPhone。我已尝试使用自定义UIButton类,但无论我做什么标题(数字0,1,2 ......)都没有显示在按钮中(圆形按钮在内部空白)。我不想为每个10个按钮重复相同的代码。我正在使用swift。
答案 0 :(得分:0)
let numberButton = UIButton(type: .System)
numberButton.frame = CGRectMake(20, 20, 100 , 100 )
numberButton.layer.borderColor = UIColor.darkGrayColor().CGColor
numberButton.layer.cornerRadius = numberButton.frame.size.width / 2
numberButton.clipsToBounds = true
numberButton.backgroundColor = UIColor(red: 20/255, green: 20/255, blue: 20/255, alpha: 0.7) //Here you can change background color
numberButton.alpha = 1
numberButton.setAttributedTitle(NSAttributedString(string: "1", attributes: [NSFontAttributeName:UIFont.boldSystemFontOfSize(25),NSForegroundColorAttributeName:UIColor.whiteColor()]) , forState: .Normal) //Here you can change the number
numberButton.setTitleShadowColor(UIColor.greenColor(), forState: .Normal)
self.view.addSubview(numberButton)