如何设置标签文本归因于其他行显示的文字.. 我的代码
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];
答案 0 :(得分:1)
对于新行使用\ 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];
我希望它会对你有所帮助。
答案 1 :(得分:1)
你试过这个解决方案吗?
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];
答案 2 :(得分:0)
要以多行显示,请使用\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
答案 3 :(得分:0)
你可以这样做:
NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc] initWithString:@"YOUR_STRING"];
clickLabel.attributedText = attrStr;
并同时做两件事:
clickLabel.numberOfLines = 2;
答案 4 :(得分:0)
它正常工作,为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];