【问题标题】:UILabel text wrap not working in iPhone?UILabel 文本换行在 iPhone 中不起作用?
【发布时间】:2012-10-17 06:11:01
【问题描述】:

我有一个 UILabel 并且它应该显示文本它将是多长时间。所以 UILineBreakModeWordWrap 的概念已经消失但它对我不起作用..如果文本不适合该行那么它应该自动出现在下一行

UILabel *lblMyLable = [[[UILabel alloc] initWithFrame:CGRectMake(10,118, 600, 40)]autorelease];
    lblMyLable.lineBreakMode = UILineBreakModeWordWrap;
    lblMyLable.numberOfLines = 0;//Dynamic
    lblMyLable.tag=1301;
    lblMyLable.backgroundColor = [UIColor clearColor];
    lblMyLable.text = [NSString stringwithformat:@"%@ %@ %@ %@ %@ %@",id,name,address,city,state,country];
    [self.view addSubview:lblMyLable];

但是在这里显示 id、name 和 address 之后,剩下的部分被剪掉了..我看不到 它..我的搜索方式是,如果不适合一行,那么它应该从第一行停止的位置开始自动跳转到下一行。我该怎么做?

【问题讨论】:

    标签: iphone xcode word-wrap


    【解决方案1】:
    NSString *str = @"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sh";
    NSString *str1 = @"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sh";
    NSString *str2 = @"xyz";
    NSString *str3 = @"xyz";
    NSString *str4 = @"xyz";
    NSString *str5 = @"xyz";
    NSString *str6 = @"xyz";
    NSString *str7 = @"xyz";   
    
    UILabel *lblMyLable = [[UILabel alloc] initWithFrame:CGRectMake(10,10, 200, 40)];
    
    lblMyLable.numberOfLines = 0;
    
    lblMyLable.backgroundColor = [UIColor clearColor];
    
    lblMyLable.text = [NSString stringWithFormat:@"%@,%@,%@,%@,%@,%@,%@,%@",str,str1,str2,str3,str4,str5,str6,str7];
    
    [lblMyLable sizeToFit];
    
    [self.view addSubview:lblMyLable];
    

    【讨论】:

    • @arizah:在 lblMyLable.text 中写数百行并检查它。它运行良好。
    【解决方案2】:

    UILable 的高度太小,看不到线条

    将高度设置为大于40的小瓶

    UILabel *lblMyLable = [[UILabel alloc] initWithFrame:CGRectMake(10,118, 600, 240)];
    

    【讨论】:

      【解决方案3】:

      这对你有帮助

      lblMyLable.numberOfLines = 0;
      lblMyLable.text = [NSString stringwithformat:@"%@ %@ %@ %@ %@ %@",id,name,address,city,state,country];
      [lblMyLable sizeToFit];
      

      【讨论】:

        猜你喜欢
        • 2015-08-07
        • 1970-01-01
        • 1970-01-01
        • 2015-03-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-06-20
        • 1970-01-01
        相关资源
        最近更新 更多