iOS项目实战经验累积01

1.打电话
    // 告诉系统要拨打那个电话号码
    NSURL *url = [NSURL URLWithString:@"tel://10010"];  // sms 发短信
    // 拨打电话号码
    [[UIApplication sharedApplication] openURL:url];
2.scrollView 点击屏幕回收键盘
遵循手势代理

    // 1.为scrollview添加手势识别器
    UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                                                      action:@selector(lyh_tapGesture)];
    singleFingerOne.delegate =self;
    [self.view addGestureRecognizer:singleFingerOne];

- (void)lyh_tapGesture
{
    [self.fd_content_Tf resignFirstResponder];
    [self.phone_qq_Tf resignFirstResponder];
}
3.textView 限制输入个数
遵循textView代理 
#define kMaxInputNumber 20 // textView输入最大个数量

- (void)textViewDidChange:(UITextView *)textView
{
    UITextRange *selectedRange = [textView markedTextRange];
    //获取高亮部分
    UITextPosition *pos = [textView positionFromPosition:selectedRange.start offset:0];
    
    //如果在变化中是高亮部分在变,就不要计算字符了
    if (selectedRange && pos) {
        return;
    }
    
    NSString  *nsTextContent = textView.text;
    NSInteger existTextNum = nsTextContent.length;
    
    if (existTextNum > kMaxInputNumber)
    {
        //截取到最大位置的字符(由于超出截部分在should时被处理了所在这里这了提高效率不再判断)
        NSString *s = [nsTextContent substringToIndex:kMaxInputNumber];
        [textView setText:s];
        // 最大就提示
        NSString *message = [NSString stringWithFormat:@"最多只能输入%i个字", kMaxInputNumber];
      UIAlertView * alert=[[UIAlertView alloc] initWithTitle:@"提示" message: message delegate:nil cancelButtonTitle:@"返回" otherButtonTitles: nil];
        // 我使用的SV_HUD
        //NSString *message = [NSString stringWithFormat:@"最多只能输入%i个字",kMaxInputNumber];
        //[SVProgressHUD showErrorWithStatus:message];

    }
    
    //不让显示负数
    self.number_Lb.text = [NSString stringWithFormat:@"%ld/%d",MAX(0,kMaxInputNumber - existTextNum),kMaxInputNumber];
}

你可能感兴趣的:(iOS项目实战经验累积01)