[英]how can set the label text Attributed?
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];
For new line use \\n and set numberOfLines more than 1 as follows 对于新行,请使用\\ n并将numberOfLines设置为大于1,如下所示
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. 希望对您有帮助。
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];
To show in multiple lines use \\n
and numberOfLines
要显示多行,请使用
\\n
和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
You can do it like this: 您可以这样做:
NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc] initWithString:@"YOUR_STRING"];
clickLabel.attributedText = attrStr;
and do both : 并同时做两个:
clickLabel.numberOfLines = 2;
Its working, set appropriate height for the clickLabel. 它的工作方式是为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];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.