#import "BIDViewController.h"
@interface BIDViewController ()
@property (weak, nonatomic) IBOutlet UILabel *headLine;
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet UIButton *onLineButton;
@end
@implementation BIDViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//标题的可变属性化字符串
NSMutableAttributedString *title=[[NSMutableAttributedString alloc] initWithString:self.onLineButton.currentTitle];
[title addAttributes:@{NSStrokeWidthAttributeName:@5, NSStrokeColorAttributeName:self.onLineButton.tintColor} range:NSMakeRange(0, [title length])];
//设置属性化标题
[self.onLineButton setAttributedTitle:title forState:UIControlStateNormal];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];
tapGesture.cancelsTouchesInView = NO;
[self.view addGestureRecognizer:tapGesture];
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self userPerferredFonts];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(preferredfeetsChanged) name:UIContentSizeCategoryDidChangeNotification object:nil];
}
-(void)preferredfeetsChanged:(NSNotification *)notification{
[self userPerferredFonts];
}
-(void)userPerferredFonts{
self.textView.font=[UIFont preferredFontForTextStyle:UIFontTextStyleBody];
//设置UITextView的字体
self.headLine.font=[UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
}
//停止收听
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
//页面消失时停止收听
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIContentSizeCategoryDidChangeNotification object:nil];
}
- (IBAction)changeTextViewColorWetchButton:(UIButton *)sender {
[self.textView.textStorage addAttribute:NSForegroundColorAttributeName value:sender.backgroundColor range:self.textView.selectedRange];
//range:self.textView.selectedRange 选中的字的范围
}
- (IBAction)addlunkuo {//为字体添加轮廓
[self.textView.textStorage addAttributes:@{NSStrokeWidthAttributeName:@-3, NSStrokeColorAttributeName:[UIColor blueColor]} range:self.textView.selectedRange];
}
- (IBAction)movelunkuo {//移除字体添加的轮廓
[self.textView.textStorage removeAttribute:NSStrokeWidthAttributeName range:self.textView.selectedRange];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)viewTapped:(UITapGestureRecognizer*)tap {
//[self.nameText resignFirstResponder];
//[self.passwordText resignFirstResponder];
[self.view endEditing:YES];
}
@end