Use different font text in a Label in swift


let secondLabel=UILabel(frame: CGRectMake(0, 16, _screenWidth2, 20))

        secondLabel.textColor=UIColor.whiteColor()

        secondLabel.textAlignment=NSTextAlignment.Center

        secondLabel.font=UIFont(name: “Arial”, size: 12)

        bottomView.addSubview(secondLabel)

        

        let attrSting=NSMutableAttributedString(string: “I agree to the Terms of Service and Privacy Policy.”)

        

        NSLog(“text length is %d”, attrSting.length)

        

        attrSting.addAttribute(NSFontAttributeName, value: UIFont(name: “Helvetica-bold”, size: 14), range: NSMakeRange(15, 16))

        

        attrSting.addAttribute(NSFontAttributeName, value: UIFont(name: “Helvetica”, size: 12), range: NSMakeRange(31,4 ))

        

        attrSting.addAttribute(NSFontAttributeName, value: UIFont(name: “Helvetica-bold”, size: 14), range: NSMakeRange(35, 15))

        

        secondLabel.attributedText=attrSting

Advertisements

A Quick start with Swift


1.Create UILabel in Swift programmatically

var textLabel=UILabel(frame: CGRectMake(15, 5, self.view.frame.size.width-30, 40))

        textLabel.text=tableArray[indexPath.row];

        textLabel.textColor=UIColor.blueColor()

        textLabel.textAlignment=NSTextAlignment.Center

        cell.addSubview(textLabel)


2. Add border using Swift

textLabel.layer.borderColor=UIColor.orangeColor().CGColor

textLabel.layer.borderWidth=2.0


3. Move form one Window to Another window using Swift

let challengeTable = self.storyboard?.instantiateViewControllerWithIdentifier(“challangeTable”)as ChallengeTable

            

            self.navigationController?.pushViewController(challengeTable, animated: true)

— – – where challangeTable is identifier id and ChallengeTable is Swift class


4. UIButton using Swift

var cancelButton=UIButton(frame: CGRectMake(self.view.frame.size.width30, 0, 30, 30))

        cancelButton.titleLabel?.text=“X”

        cancelButton.titleLabel?.textColor=UIColor.whiteColor()

        cancelButton.backgroundColor=UIColor.blackColor()

        self.view.addSubview(cancelButton)


5. WebView using Swift

var htmlRequest=NSURLRequest(URL:NSURL(string: https://eriphonedevelopers.wordpress.com/”))

        

        var webView=UIWebView(frame: CGRectMake(15, 15, screenWidth30, screenHeight116))

        webView.loadRequest(htmlRequest)

        tocView.addSubview(webView)


6. Getting Screen size in Swift

var screenWidth=UIScreen.mainScreen().bounds.width

        var screenHeight=UIScreen.mainScreen().bounds.height