ios UILabel 的创建

UILabel *labelp = [[UILabel alloc]initWithFrame:CGRectMake(10, 50,70, 50)]; // 确定labelp的位置
    labelp.text = @"人:";//labelp的内容
    labelp.textColor = [UIColor blackColor];//labelp的文字颜色
    [self.view addSubview:labelp];//加载labelp
  //    创建一个内容为 人 的label
    
    
    UILabel *labelr = [[UILabel alloc]initWithFrame:CGRectMake(10, 250,70, 50)];// 确定labelr的位置
    labelr.text = @"餐厅:";//labelr的内容
    labelr.textColor = [UIColor blackColor];//labelr的文字颜色
    [self.view addSubview:labelr];//加载labelr
//    创建一个内容为 餐厅 的label
    
    
    UILabel *labelt = [[UILabel alloc]initWithFrame:CGRectMake(10, 450,70, 50)];// 确定labelt的位置
    labelt.text = @"套餐:";//labelt的内容
    labelt.textColor = [UIColor blackColor];//labelt的文字颜色
    [self.view addSubview:labelt];//加载labelt
//    创建一个内容为 套餐 的label

 创建很多的label可以创建成类然后调用

-(UILabel *)creat_label_with_text:(NSString *)text :(CGRect)frame
{
    UILabel *label = [[UILabel alloc]initWithFrame:frame];//label的位置
    label.text = text;//label的内容
    label.textColor = [UIColor blackColor];//label文字颜色
    label.font = [UIFont boldSystemFontOfSize:20];//label字体大小 并且加粗
    [self.view addSubview:label];//加载label
    return label;
}//创建有内容的label

-(UILabel *)creat_label_with_board :(CGRect)frame
{
    UILabel *choose_label = [[UILabel alloc]initWithFrame:frame];//label的位置
    choose_label.backgroundColor = [UIColor whiteColor];//label的背景颜色
    choose_label.layer.borderColor = [UIColor grayColor].CGColor;//label边框的颜色
    choose_label.layer.borderWidth = 0.5;//label边框的宽度
    choose_label.layer.cornerRadius = 10.0;//label边框的圆角的半径
    [self.view addSubview:choose_label];//加载label
    return choose_label;
}

-(void)creat_label
{
    
    [self creat_label_with_text:@"人:" :CGRectMake(10, 60,70, 50)];
    //    创建一个内容为 人 的label
    [self creat_label_with_text:@"餐厅:" :CGRectMake(10, 250,70, 50)];
    //    创建一个内容为 餐厅 的label
    [self creat_label_with_text:@"套餐:" :CGRectMake(10, 450,70, 50)];
    //    创建一个内容为 套餐 的label
    
    UILabel *persChoose = [self creat_label_with_board:CGRectMake(35, 110, 300, 45)];
    self.persName = persChoose;
    //    创建人名选择的label
    UILabel *restChoose =[self creat_label_with_board:CGRectMake(35, 300,300, 45)];
    self.restName = restChoose;
    //    创建餐厅选择的label
    UILabel *packChoose = [self creat_label_with_board: CGRectMake(35, 490, 300, 45)];
    self.packName = packChoose;
    //    创建套餐选择的label
}

效果如图   忽略选人和选套餐两个按钮



 

猜你喜欢

转载自404530969.iteye.com/blog/2258409