【问题标题】:Adding UILabel as subview of UIImageView hiding image view image添加 UILabel 作为 UIImageView 的子视图隐藏图像视图图像
【发布时间】:2015-03-05 06:44:28
【问题描述】:
UIImageView *newView =[[UIImageView alloc]initWithFrame:CGRectMake(0.0f, 0.0f, 15.0f, 15.0f)];
    [newView setImage:image];

    UILabel *newLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 15.0f, 15.0f)];
    newLabel.translatesAutoresizingMaskIntoConstraints = NO;
    newLabel.textAlignment = NSTextAlignmentCenter;
    newLabel.lineBreakMode = NSLineBreakByClipping;
    newLabel.adjustsFontSizeToFitWidth = YES;
    newLabel.text = labelText;
    newLabel.backgroundColor = [UIColor clearColor];
    [newView addSubview:newLabel];

【问题讨论】:

    标签: uiimageview uilabel


    【解决方案1】:

    我在您的代码中添加了两个新行并修改了一行,希望对您有所帮助..

    UIImageView *newView =[[UIImageView alloc]initWithFrame:CGRectMake(0.0f, 0.0f, 150.0f, 150.0f)];
    [newView setImage:[UIImage imageNamed:@"3.png"]];//Modified line
    [self.view addSubview:newView];//New added line
    
    UILabel *newLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 150.0f, 150.0f)];
    newLabel.translatesAutoresizingMaskIntoConstraints = NO;
    newLabel.textAlignment = NSTextAlignmentCenter;
    newLabel.lineBreakMode = NSLineBreakByClipping;
    newLabel.adjustsFontSizeToFitWidth = YES;
    newLabel.text = @"labelText";
    newLabel.backgroundColor = [UIColor clearColor];
    [newView addSubview:newLabel];
    

    如果你的 newLabel 文本很长,你可以添加这个..

    newLabel.numberOfLines = 3;//New added line
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-12
      • 1970-01-01
      • 2016-06-10
      相关资源
      最近更新 更多