0

The following code don't show up multiline text

UIButton * viewedYou = [UIButton buttonWithType: UIButtonTypeCustom];
viewedYou.frame = CGRectMake(0.0,0.0,61,30);
[viewedYou setTitle:@"Viewed\nYou" forState:UIControlStateNormal];
[self.view addSubview:viewedYou];
Roki
  • 2,680
  • 1
  • 22
  • 21
  • possible duplicate of [How do you add multi-line text to a UIButton?](http://stackoverflow.com/questions/604632/how-do-you-add-multi-line-text-to-a-uibutton) or [UIButton Multiline Text](http://stackoverflow.com/questions/3239793/uibutton-multiline-text) – jscs May 21 '11 at 01:30

2 Answers2

1

Duplicate question: UIButton : Multiline text . But in your case:

    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];
Community
  • 1
  • 1
Dam
  • 244
  • 1
  • 3
  • 14
1

do

viewedYou.titleLabel.numberOfLines = 0;
viewedYou.titleLabel.lineBreakMode = UILineBreakModeWordWrap;
Deepak Danduprolu
  • 44,595
  • 12
  • 101
  • 105