UITextView+Button

 

#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

转载于:https://www.cnblogs.com/ai8697/p/4614592.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值