0

how can set the label text Attributed so that the text shown on other line.. My Code

clickLabel = [[UILabel alloc]initWithFrame:CGRectMake(27, 340, 300, 95)];
clickLabel.attributedText=@"Click on Done,You agree to accept Terms and  Conditions and Privacy Policy of Ios App";
clickLabel.textColor=[UIColor blueColor];
UIFont *boldFont2 = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];
[clickLabel setFont:boldFont2];
[scrollView addSubview:clickLabel];
narner
  • 2,908
  • 3
  • 26
  • 63
Nisha Gupta
  • 275
  • 1
  • 14

5 Answers5

1

For new line use \n and set numberOfLines more than 1 as follows

clickLabel = [[UILabel alloc]initWithFrame:CGRectMake(27, 340, 300, 95)];
clickLabel.attributedText=@"Click on Done,You agree to accept \n Terms and  Conditions and Privacy Policy of Ios App";
clickLabel.numberOfLines  = 2;
clickLabel.textColor=[UIColor blueColor];
UIFont *boldFont2 = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];
[clickLabel setFont:boldFont2];
[scrollView addSubview:clickLabel];

I hope it will help you.

Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184
Pravin Tate
  • 1,145
  • 8
  • 18
1

Have you tried this solution?

clickLabel = [[UILabel alloc]initWithFrame:CGRectMake(27, 340, 300, 95)];

clickLabel.attributedText = [[NSAttributedString alloc] initWithString:@"Click on Done,You agree to accept\nTerms and Conditions and Privacy Policy of Ios App" attributes:nil] ;

clickLabel.textColor=[UIColor blueColor];

clickLabel.numberOfLines = 0;

UIFont *boldFont2 = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];
[clickLabel setFont:boldFont2];
[scrollView addSubview:clickLabel];
mrtna
  • 191
  • 8
0

To show in multiple lines use \n and numberOfLines

clickLabel.text = @"Click on Done, You agree to accept\nTerms and  Conditions and Privacy Policy of iOS App";
clickLabel.numberOfLines = 0; // 0 mean any number of lines
Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184
0

You can do it like this:

NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc] initWithString:@"YOUR_STRING"];

clickLabel.attributedText = attrStr;

and do both :

  • clickLabel.numberOfLines = 2;
  • add \n before your words.
0

Its working, set appropriate height for the clickLabel.

UILabel * clickLabel = [[UILabel alloc]initWithFrame:CGRectMake(27, 340, 300, 100)];
clickLabel.attributedText = [[NSAttributedString alloc] initWithString:@"Click on Done,You agree to accept\nTerms and Conditions and Privacy Policy of Ios App" attributes:nil] ;
clickLabel.textColor=[UIColor blueColor];
clickLabel.numberOfLines = 0;
UIFont *boldFont2 = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];
[clickLabel setFont:boldFont2];
[self.view addSubview:clickLabel];
Nandha K
  • 71
  • 5