Attributes-iOS初学

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];

Attributes-iOS初学_第1张图片


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

[self.body.textStorage addAttributes:@{NSStrokeWidthAttributeName:@3,
                                           NSStrokeColorAttributeName:[UIColor blackColor]}
                                   range:self.body.selectedRange];
Attributes-iOS初学_第2张图片

设置颜色:

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




你可能感兴趣的:(ios,Objective-C,字体)