Tuesday, December 15, 2015

Create UILabel / UIButton and UITextView Programmatically in ios


-(UILabel *)settingLabelProperties:(UILabel *)myLabel{
    myLabel = [[UILabel allocinit];
    //myLabel.text = @"XYZ";
    myLabel.textColor = [UIColor whiteColor];
    myLabel.backgroundColor = [UIColor clearColor];
    myLabel.numberOfLines = 0;
    myLabel.font = [UIFont systemFontOfSize:17.0];
    [self.view addSubview:myLabel];
    return myLabel;
}

-(UITextView *)settingTextViewProperties:(UITextView *)myLabel{
    myLabel = [[UITextView allocinit];
    //myLabel.text = @"XYZ";
    myLabel.textColor = [UIColor whiteColor];
    myLabel.backgroundColor = [UIColor clearColor];
    myLabel.font = [UIFont systemFontOfSize:17.0];
    myLabel.selectable = FALSE;
    myLabel.editable = FALSE;
    myLabel.scrollEnabled = FALSE;
    [myLabel resignFirstResponder];
    myLabel.textAlignment = NSTextAlignmentJustified;
    [self.view addSubview:myLabel];
    return myLabel;
}

-(UIButton *)settingButtonProperties:(UIButton *)myLabel{
    myLabel = [[UIButton allocinit];
    //myLabel.text = @"XYZ";
    myLabel.titleLabel.textColor = [UIColor whiteColor];
    myLabel.backgroundColor = [UIColor clearColor];
    myLabel.titleLabel.font = [UIFont systemFontOfSize:20.0];
    myLabel.titleLabel.textAlignment = NSTextAlignmentCenter;
    [myLabel setBackgroundImage:[UIImage imageNamed:@"btn-bg.png"]forState:UIControlStateNormal];
    [self.view addSubview:myLabel];
    return myLabel;

}

Note : also set the frame and text of UILabel / UIButton and UITextView.

No comments:

Post a Comment