UIlabel设置背景为圆形

直接对label的cornerRadius进行设置

   var text = UILabel(frame: CGRectMake(10,30,UIScreen.mainScreen().bounds.size.width - 20,200))
        text.text = "背景为圆形 "
        text.backgroundColor = self.view.backgroundColor
        text.textColor = UIColor.whiteColor()
        text.font = UIFont.systemFontOfSize(22)
        text.textAlignment = NSTextAlignment.Center
        label.layer.cornerRadius = label1.bounds.size.width/2
        self.view.addSubview(text)

你可能感兴趣的:(swift学习日志)