can't get word wrap to work on UIButton

前端 未结 1 1496
别跟我提以往
别跟我提以往 2021-01-20 03:06

I have a simple UIButton and try to get word wrap but it always shows the text in one line exceeding the button size.

 NSString * text = NSLocalizedString(@\         


        
相关标签:
1条回答
  • 2021-01-20 03:18

    Try:

    _continueBtn.titleLabel.numberOfLines = 0;
    

    I've tried next code:

    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame = CGRectMake(20, 20, 70, 50);
    button.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
    button.titleLabel.textAlignment = NSTextAlignmentCenter;
    [button setTitle:@"start loading"
            forState:UIControlStateNormal];
    [self.view addSubview:button];
    

    It's working good for me:

    screenshot

    0 讨论(0)
提交回复
热议问题