以下代码未显示多行文字
UIButton * viewedYou = [UIButton buttonWithType: UIButtonTypeCustom];
viewedYou.frame = CGRectMake(0.0,0.0,61,30);
[viewedYou setTitle:@"Viewed\nYou" forState:UIControlStateNormal];
[self.view addSubview:viewedYou];
答案 0 :(得分:1)
重复问题:UIButton : Multiline text。 但在你的情况下:
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];
答案 1 :(得分:1)
DO
viewedYou.titleLabel.numberOfLines = 0;
viewedYou.titleLabel.lineBreakMode = UILineBreakModeWordWrap;