在我的应用程序中,我想在一个UITextView中编写15个字体大小属性文本(如粗体,斜体,下划线)。
并希望在另一个 UITextView 中以 35 字体大小属性文本编写相同的文本。
我在UITextView中完成了所有属性文本写入任务。
但是不要知道如何在同一时间以不同的字体大小在另一个UITextView中编写相同的文本。
我需要为UITextView定义不同的NSMutableParagraphStyle。
我的代码只是粗体文本是
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
UIFont *font = [UIFont fontWithName:@"Helvetica-Bold" size:15];
NSDictionary *attributes = @{NSFontAttributeName :font};
[txtView1 setTypingAttributes:attributes];
UIFont *font35 = [UIFont fontWithName:@"Helvetica-Bold" size:35];
NSDictionary *attributes35 = @{NSFontAttributeName :font35};
[txtView2 setTypingAttributes:attributes35];
NSMutableAttributedString *mat = [txtViewOfNotes.attributedText mutableCopy];
[mat addAttributes:@{NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)} range:NSMakeRange (range.location-1, 1)];
txtView1.attributedText = mat;
NSMutableAttributedString *mat = [txtViewOfNotes.attributedText mutableCopy];
[mat addAttributes:@{NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)} range:NSMakeRange (range.location-1, 1)];
txtView2.attributedText = mat;
}
任何类型的想法,代码或教程都将是很大的帮助。
我认为您需要添加属性,然后更改两个文本视图的文本。因此,请使用如下:
NSMutableAttributedString *title = [[NSMutableAttributedString alloc]initWithString:text];
UIFont *font = [UIFont fontWithName:@"Arial" size:15];
[title addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, title.length)];
titleView1.attributedText = title;
UIFont *font = [UIFont fontWithName:@"Arial" size:35];
[title addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, title.length)];
titleView1.attributedText = title;