如何设置标签文本属性?
how can set the label text Attributed?
如何设置标签文本属性,以便文本显示在另一行..
我的代码
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];
要以多行显示,请使用 \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
你可以这样做:
NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc] initWithString:@"YOUR_STRING"];
clickLabel.attributedText = attrStr;
两者都做:
clickLabel.numberOfLines = 2;
- 在你的话前加上\n。
对于新行,使用 \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];
希望对你有所帮助
你尝试过这个解决方案吗?
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];
成功了,为 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];
如何设置标签文本属性,以便文本显示在另一行.. 我的代码
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];
要以多行显示,请使用 \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
你可以这样做:
NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc] initWithString:@"YOUR_STRING"];
clickLabel.attributedText = attrStr;
两者都做:
clickLabel.numberOfLines = 2;
- 在你的话前加上\n。
对于新行,使用 \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];
希望对你有所帮助
你尝试过这个解决方案吗?
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];
成功了,为 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];