永发信息网

ios中textview的标签颜色怎么设置

答案:1  悬赏:40  手机版
解决时间 2021-02-24 00:57
  • 提问者网友:像風在裏
  • 2021-02-23 01:35
ios中textview的标签颜色怎么设置
最佳答案
  • 五星知识达人网友:野味小生
  • 2021-02-23 01:47
#import "ViewController.h"
#import
#import

@interface ViewController ()

@property (strong, nonatomic) IBOutlet UITextView *textView;
@end

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

NSMutableAttributedString * attributedTextString = [[NSMutableAttributedString alloc] initWithString:@"hahahahhahahahhiuhgilgliuglugugguglgjlgjgjgljgjgjuguyguydgasjgfglsa,g和环境的还是觉得还是计划经济健康来了来了健康哈哈哈哈哈哈"];

//设置的是字的颜色
[attributedTextString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 5)];
//设置的是字的背景颜色
[attributedTextString addAttribute:NSBackgroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(0, 5)];
//设置的时字的字体及大小
[attributedTextString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:16] range:NSMakeRange(0, 5)];

self.textView.attributedText = attributedTextString;

[self.view setBackgroundColor:[UIColor whiteColor]];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯