25 Mar 2017

How to create a basic UIButton, UILabel Programmatically...




How to create a basic UIButton, UILabel Programmatically...


  /*================ UIButton has different ButtonTypes ================ */ 

    self.system=[UIButton buttonWithType:UIButtonTypeSystem];
    self.system.frame=CGRectMake(80, 220, 100, 100);
//    self.system.backgroundColor=[UIColor cyanColor];
    [self.system setTitle:@"SystemBtn" forState:UIControlStateNormal];
    self.system.layer.cornerRadius = 50;
    self.system.backgroundColor=[UIColor colorWithRed:0.5 green:1 blue:0.6 alpha:0.8];
    [self.system setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    self.system.tag=4;
    
    [self.system addTarget:self action:@selector(buttonsAction1:) forControlEvents:UIControlEventTouchCancel];


 /*==================== Label ===================== */


    self.onLabel=[[UILabel alloc]init];
    self.onLabel.frame=CGRectMake(20, 400, 380, 100);
    self.onLabel.backgroundColor=[UIColor lightGrayColor];
    self.onLabel.textAlignment=1;
    self.onLabel.font=[UIFont fontWithName:@"Arial" size:36];
    self.onLabel.textColor=[UIColor redColor];
    [self.view addSubview:self.onLabel];

-(void)buttonsAction1:(UIButton *)sender
{
    self.onLabel.text=[NSMutableString stringWithFormat:@" %ld ",(long)sender.tag];
    self.label.text=@"TouchUpInside";
    
}

No comments:

Post a Comment

Recent Posts

Codable demo

Link: https://www.dropbox.com/s/kw7c1kgv1628bh7/codableDemo.zip?dl=0