Objective c 可可触摸按钮中的多行文字?

Objective c 可可触摸按钮中的多行文字?,objective-c,cocoa-touch,Objective C,Cocoa Touch,以下代码不显示多行文本 UIButton * viewedYou = [UIButton buttonWithType: UIButtonTypeCustom]; viewedYou.frame = CGRectMake(0.0,0.0,61,30); [viewedYou setTitle:@"Viewed\nYou" forState:UIControlStateNormal]; [self.view addSubview:viewedYou]; 重复问题:。 但就你而言: UIB

以下代码不显示多行文本

UIButton * viewedYou = [UIButton buttonWithType: UIButtonTypeCustom];
viewedYou.frame = CGRectMake(0.0,0.0,61,30);
[viewedYou setTitle:@"Viewed\nYou" forState:UIControlStateNormal];
[self.view addSubview:viewedYou];
重复问题:。 但就你而言:

    UIButton * viewedYou = [UIButton buttonWithType: UIButtonTypeCustom];
    viewedYou.frame = CGRectMake(0.0,0.0,61,30);

UILabel* viewedYouLabel = [[UILabel alloc] initWithFrame: viewedYou.bounds];
    viewedYouLabel.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
    viewedYouLabel.textAlignment = UITextAlignmentCenter;
    viewedYouLabel.frame = CGRectMake(0.0,0.0,61,30);
    viewedYouLabel.numberOfLines =2;
    viewedYouLabel.text = @"Viewed\nYou";
    [viewedYou addSubview: viewedYouLabel];

    [self.view addSubview:viewedYou];

或的可能副本
viewedYou.titleLabel.numberOfLines = 0;
viewedYou.titleLabel.lineBreakMode = UILineBreakModeWordWrap;