iOS知多少IOS开发iOS笔记

iOS中以set开头和add开头的方法规律

2015-11-11  本文已影响648人  船长_
#pragma mark ---------- test1-------------
    UILabel *label = [[UILabel alloc] init];
    label.frame = CGRectMake(100, 200, 200, 50);
    [self.view addSubview:label];
    
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"testtest"];
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[NSFontAttributeName] = [UIFont systemFontOfSize:15];
    [string setAttributes:dict range:NSMakeRange(0, 2)];

    NSMutableDictionary *dict2 = [NSMutableDictionary dictionary];
    dict2[NSForegroundColorAttributeName] = [UIColor blueColor];
    dict2[NSUnderlineStyleAttributeName] = @YES;
    [string setAttributes:dict2 range:NSMakeRange(0, 3)];
    
    label.attributedText = string;
#pragma mark -------- test2-----------------------
    UILabel *labelTest = [[UILabel alloc] init];
    labelTest.frame = CGRectMake(100, 300, 200, 50);
    [self.view addSubview:labelTest];
    
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"1234567"];
    NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
    dictM[NSFontAttributeName] = [UIFont systemFontOfSize:18];
    [attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(0, 3)];
    [attributedString addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:18] range:NSMakeRange(2, 3)];
    [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor]range:NSMakeRange(0, 4)];
    
    labelTest.attributedText = attributedString;

oc中很多这样类似的方法规律,再比如UIButton

   UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
   btn.frame  = CGRectMake(100,100,100, 50);
   
   // 会累加
   [btn addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpOutside];
   [btn addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchDownRepeat];
   
   // 会覆盖 
   [btn setTitle:@"111" forState:UIControlStateNormal];
   [btn setTitle:@"222" forState:UIControlStateNormal];
   
   [self.view addSubview:btn];
上一篇下一篇

猜你喜欢

热点阅读