Attributes-iOS初学

来源:互联网 发布:c语言软件 编辑:程序博客网 时间:2024/05/29 19:47

Attributes-iOS初学

- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view, typically from a nib.    //获取可变attributes    NSMutableAttributedString *title = [[NSMutableAttributedString alloc]initWithString:self.outlineButton.currentTitle];    //设置attributes    [title setAttributes:@{NSStrokeWidthAttributeName:@3,                           NSStrokeColorAttributeName:self.outlineButton.tintColor}                   range:NSMakeRange(0, [title length])];    //attribute放回    [self.outlineButton setAttributedTitle:title forState:UIControlStateNormal];}






@-3:描边+填充。

[self.body.textStorage addAttributes:@{NSStrokeWidthAttributeName:@-3,                                           NSStrokeColorAttributeName:[UIColor blackColor]}                                   range:self.body.selectedRange];



@3:只描边,不填充,字体颜色失效。

[self.body.textStorage addAttributes:@{NSStrokeWidthAttributeName:@3,                                           NSStrokeColorAttributeName:[UIColor blackColor]}                                   range:self.body.selectedRange];


设置颜色:

- (IBAction)changeColor:(UIButton *)sender{    [self.body.textStorage addAttribute:NSForegroundColorAttributeName                                   value:sender.backgroundColor //通过sender传递选中颜色。                                  range:self.body.selectedRange];}




1 0
原创粉丝点击