Tag: uitextfield

使UITextField有一个静态和属性前缀

我想创build一个UITextField ,它有一个静态的前缀,并且用户不能编辑或删除,同时它也被归为浅灰色的字体颜色。 文本字段的可编辑部分应始终以黑色显示。 下面给出一个例子: 它本质上是用于input一个用户名,带有一个不断加前缀的域。 我已经尝试使用textFieldShouldClear和textField:shouldChangeCharactersInRange:replacementString:与NSMutableAttributedString一起委托方法,但根本无法破解它: – (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSMutableAttributedString *text = [textField.attributedText mutableCopy]; [text addAttribute:NSForegroundColorAttributeName value:[UIColor grayColor] range:NSMakeRange(0, 7)]; if (textField.text.length > 7) { [text addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(7, textField.attributedText.length – 7)]; } [text addAttribute:NSFontAttributeName value:[UIFont gothamFontForSize:textField.font.pointSize andWeight:kGothamLight] range:NSMakeRange(0, textField.attributedText.length)]; return range.location > 6; } – (BOOL)textFieldShouldClear:(UITextField *)textField { NSMutableAttributedString […]

在UITableView中的自定义原型单元格中,UITextField值将replace为其他原型单元格

我采取了一个UITableView和里面,我已经使用了2个prototype单元格,现在在这些原型单元格中,我已经采取了1个UITextField 。 现在,当我运行应用程序,并在第一个原型单元格中input值,然后滚动UITableView ,然后第一个原型单元格的文本字段值来最后原型单元格的文本字段值。 所以它每次我滚动或滚动。 有时它变成空白。 这是我的代码 – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if(indexPath.row==0) { Client_MobileCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier_MobileCell forIndexPath:indexPath]; cell.lblTitle.text = [arrTitle objectAtIndex:indexPath.row]; cell.txtMobile.placeholder = [arrPlaceholder objectAtIndex:indexPath.row]; // cell.txtMobile.tag = indexPath.row+100; return cell; } else { // Client_Common_Cell *cell = (Client_Common_Cell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier_CommonCell forIndexPath:indexPath]; Client_Common_Cell *cell = (Client_Common_Cell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier_CommonCell]; // cell.txtCommon.tag […]

iPhone中textfieldshouldendediting和textfieldDidendediting之间的区别

textFieldShouldendEditing和textfieldDidEndEditing之间有什么区别,什么时候应该使用每个方法?

UITextField在编辑时更改字体

我遇到了同样的问题,因为在编辑模式下 , UITextField的自定义字体发生了变化,并且可以真正解决这个问题。 我有4个UITextFields,我在ViewDidLoad中分配自定义字体。 这个工作,他们看起来不错,但是当点击一个字段来编辑文本字体变回默认文本,当resignedfirstresponder自定义字体回来。 – (void)viewDidLoad { [super viewDidLoad]; { UIFont *twoDumb = [UIFont fontWithName:@"Dumb" size:20.f]; lbl1.font = twoDumb; broughtForward.font = twoDumb; lbl2.font = [UIFont fontWithName:@"Dumb" size:24.f]; amountTextfield.font = twoDumb; lbl3.font = twoDumb; 如果我使用系统字体,那么文本字段的工作原理应该如此,所以这个字体文件一定有什么关系呢?

如何在警报控制器的文本字段中使用数字键盘

我正在尝试调用一个具有文本字段的警报控制器。 但是我想立即显示数字键盘,因为用户只需要input数字。 我尝试了以下,但它不工作。 let alert = UIAlertController(title: "New Rating", message: "Rate this!", preferredStyle: UIAlertControllerStyle.Alert) let cancelAction = UIAlertAction(title: "Cancel", style: .Default, handler: { (action: UIAlertAction!) in }) let saveAction = UIAlertAction(title: "Save", style: .Default, handler: { (action: UIAlertAction!) in let textField = alert.textFields![0] as UITextField textField.keyboardType = UIKeyboardType.NumberPad self.updateRating(textField.text) }) alert.addTextFieldWithConfigurationHandler { (textField: UITextField!) in […]

UITextField:在input时限制允许的最大值(数字)

我有一个UITextField ,我想限制在该字段中允许的最大input值为1000.这是当用户在内部input数字时,一旦input值大于999,input字段中的值将不会更新除非用户input小于1000的值。 我想我应该使用UITextField委托来限制input: – (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { //How to do } 但我不知道如何实现它。 有什么build议么? ==========更新============= 我的input字段不仅允许用户input整数,而且浮点值如999,03

在Swift中popup的datePickerView中添加完成button?

我想在Swift中popup的datePickerView中添加一个完成button。 这里是代码: @IBOutlet var datePicker: UITextField! @IBAction func dateTextInputPressed(sender: UITextField) { var datePickerView : UIDatePicker = UIDatePicker() datePickerView.datePickerMode = UIDatePickerMode.Date sender.inputView = datePickerView datePickerView.addTarget(self, action: Selector("handleDatePicker:"), forControlEvents: UIControlEvents.ValueChanged) } func handleDatePicker(sender: UIDatePicker) { var dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd" datePicker.text = dateFormatter.stringFromDate(sender.date) } 我可以使用此代码成功popup一个datePickerView。 但问题是我selectdate后,它没有一个“完成”button,所以我不能解雇它。 那么我怎样才能把完成button添加到它呢? 谢谢!

我在哪里可以得到UISearchBar中使用的放大镜图标?

我正在使用UITextField作为UISearchBar替代品,并用这个疯狂的代码从原始的UISearchBar “偷取”放大镜图标: UISearchBar *originalSearchBar = [[UISearchBar alloc] init]; for (UIView *searchBarSubview in [originalSearchBar subviews]) { if([searchBarSubview isKindOfClass:[UITextField class]]) { UITextField *textField = (UITextField *)searchBarSubview; [_textField setLeftView:[textField leftView]]; [_textField setLeftViewMode:UITextFieldViewModeAlways]; } } 正如你可能猜到的,我不想用我自己的位图。 在Cocoa的某个地方没有更容易获得的放大镜图标吗?

如果我在调用textFieldShouldReturn时返回“YES”或“NO”,有什么区别

这是文本字段委托方法,但我对返回types有疑问 -(BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return NO; } 这是不同返回types的方法 -(BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return YES; } 通过我们可以隐藏在我的手机键盘。 但返回types“是”还是“否”的含义是什么? 我没有看到任何区别。

ios uitextfield喜欢笔记

我希望我的uitextfield看起来像iPhone的笔记,黄色的线条。什么是最好的方式来做到这一点? 提前致谢!