iPhone 可能不常用的代码

 


 

1、给TableViewCell设置点击高亮

      //选中cell添加高亮
    cell.selectedBackgroundView = [[[UIView alloc] initWithFrame:cell.frame] autorelease];
    cell.selectedBackgroundView.backgroundColor = [UIColor yellowColor];
   
    //cell所在的层绘制圆角
    cell.selectedBackgroundView.layer.cornerRadius =8;
    cell.selectedBackgroundView.layer.masksToBounds = YES;

2、给TableView设置圆角 一般是给group用

    myTableView.layer.cornerRadius = 20;
    myTableView.layer.masksToBounds = YES; 

   都是在tableview层上设置的

3、给TextField 加键盘隐藏事件的一种方法

  - (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}
这个是UITextField的代理方法,要在头文件引入代理<UITextFieldDelegate>

4、限制UITextField的输入长度

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if (range.location >0)
        return NO; // return NO to not change text
    return YES;
}

还是一个代理方法,上面的0是限制的字符数目,我这里0限制只输入一个字符

中文输入会有问题,首先用联想会输入任意多个,联想几个汉字就显示几个,并且超过限制的字符不能删除。。。很怪异

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if(textField.text.length != 0)
        textField.text = [textField.text substringToIndex:1];
}

可以用上面的代理来截取字符,我这里只要输入的第一个中文字符,其他的都截取掉

5、建议搞iPhone开发的都学Python吧,简单强大,mac里自带Python ,常用模块都包含着,至少操作sqlite,写爬虫是不用第三方模块的。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值