Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create a UILabel & UIButton programmatically in Swift

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.35k
    Comment on it

    hello friends, this is how we can create a UIButton and UILabel in swift.

    Set a UILabel in swift

            var label = UILabel(frame: CGRectMake(100, 100, self.view.bounds.size.width, 50))
            label.center = self.view.center
            label.textAlignment = NSTextAlignment.Center
            label.text = test label
            label.textColor = UIColor.grayColor()
            self.view.addSubview(label)
    

    Set a UIButton in swift

    let testButton = UIButton.buttonWithType(UIButtonType.System) as! UIButton
            testButton.backgroundColor = UIColor.orangeColor()
            testButton .setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
            testButton.setTitle(click here, forState: UIControlState.Normal)
            testButton.frame = CGRectMake(self.view.bounds.size.width,100, 100, 50)
            testButton.addTarget(self, action: "buttonClicked:, forControlEvents: UIControlEvents.TouchUpInside)
    
            self.view.addSubview(testButton)
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: