iphone - UIButton 导致 UITextField 字删除

标签 iphone ios objective-c xcode uibutton

我对使用 UIButton 删除单词有疑问

例如UITextField 中有 10 个字母。我通过按下 UIButton 进行编码,这样我就可以使用退格键或删除功能来一个一个地删除字母。但是,我只希望用户能够删除 10 个字母中的最后 5 个字母。我怎样才能限制它?

这是我的代码,

-(IBAction)delete:(id)sender{
    if ([display.text length] != 0) {
        display.text = [display.text substringToIndex:[display.text length]-1];
    }

最佳答案

if ([display.text length] > 5) {
    display.text = [display.text substringToIndex:[display.text length]-1];
}

关于iphone - UIButton 导致 UITextField 字删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15370424/

相关文章:

ios - 无效更新: invalid number of rows in section 0

ios - 自动布局或自动调整大小

iphone - OpenGL ES 2.0 纹理

iphone - 链接到App Store

ios - 导航 Controller 推送 View Controller

ios - 更新标签使 UIImageview 不可见的线程问题

iphone - 我的 NSLog 输出在哪里?

ios - ViewController 异常改变大小

ios - 填写所有 UITextField 后,UIButton 未启用

ios - UITableView 复选标记重复