1. 程式人生 > >UIlabel設定背景為圓形

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)