uitextfield

Colored substring in UITextField

[亡魂溺海] 提交于 2019-12-11 15:55:33
问题 I would like to change the color only of particular substrings (keywords) while the user is typing in a UITextField . In the documentation I saw the property textColor but it does change the color of the entire text string, while I would like to highlight only some keywords. Is it possible? 回答1: The short answer is no. It's possible if you create your own textfield from scratch using NSAttributedStrings and CATextLayers or Core Text, but this is an incredibly complex and difficult problem.

UITextField keyboard can't type anything

风流意气都作罢 提交于 2019-12-11 15:47:26
问题 load a xib file as a UIView, and I got a UITextField form a Xib file(it just a view that contains textfield and button). But when the app launched and that textfield comes up. i cannot type any alphabet on this UITextField. But paste a text to that UITextField was OK. Why? Here is my adding code -(IBAction)showSheet{ UIView *myView = [[[NSBundle mainBundle] loadNibNamed:@"LoginViewComp" owner:self options:NULL] lastObject]; [myView setFrame:CGRectMake(0, 44, 320, 400)]; UIButton *btn1 =

TextField:shouldChangeCharactersInRange:replacementString: return trap!

穿精又带淫゛_ 提交于 2019-12-11 15:25:00
问题 Im calling UITableViewCell delegate method TextField:shouldChangeCharactersInRange:replacementString: on a custom cell that has four UITextFields and what is happening once maxlength is reached on one of the fields it dose not let you enter any text in the other fields because its always returning "no" for that initial if statement thats being satisfied. any ideas on how to get around this? I'm only testing on two fields at the moment. Thank you for any help in advance. - (BOOL)textField:

Remove rightView property from textfield swift 4

牧云@^-^@ 提交于 2019-12-11 15:19:20
问题 I'm using rightview property to a textfield if it contains some text in it. I need to remove the property if the textfield doesn't contain any text. I have searched so many links but didn't find any answer for this. Please help me. To add rightView property : let cardImage = UIImageView(image: UIImage(named: icon)) cardImage.frame = CGRect(x: 10, y: 20, width: 70, height: self.cardTxtFld.frame.size.height-20); cardImage.contentMode = UIViewContentMode.scaleAspectFit self.cardTxtFld.rightView

comma separated number with 2 digit fraction - swift

一世执手 提交于 2019-12-11 15:16:18
问题 I have a textfield that it's input is price, so I want to get both like this: 1,111,999.99 . I wrote to make it possible but there are two problems. First, after four digits and 2 fraction digit (like 1,234.00) it resets to zero. Second, I can't put fraction in it (fraction is always .00) how can i make a textfield that receives 1,111,999.99 as input? in my custom UITextfield: private var numberFormatter: NumberFormatter { let formatter = NumberFormatter() formatter.maximumFractionDigits = 2

Add row in a TableView

柔情痞子 提交于 2019-12-11 14:59:10
问题 So I have two views, the first have my TableView and the second have my TextField and I want to add a row in my TableView with the text in my TextField. For the moment I can just add row with [myTableView addObject:@"Test 1"]; [myTableView addObject:@"Test 2"]; [myTableView addObject:@"Test 3"]; Thanks for your help! - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell =

Setting isHidden to false on x amount of elements

半世苍凉 提交于 2019-12-11 14:56:27
问题 I am trying to unhide n number of elements depending on the users input into a text field. So the user enters a number between 1 - 5 in the text field then clicks submit which calls createSplit . As you can see, it unhides a view and then I want it to loop x (x being the number the user inputs) amount of times to unhide day(i)View textfield @IBAction func createSplit(_ sender: Any) { noOfExerciseView.isHidden = false let noOfDays: Int = Int(numberOfDays.text!)! for i in 1...noOfDays { day\(i

Custom TextField in UIAlertController [duplicate]

瘦欲@ 提交于 2019-12-11 14:19:05
问题 This question already has answers here : How to add textField in UIAlertController? (3 answers) Closed 2 years ago . I could add a textfield in UIAlertController using UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Title" message:@"message" preferredStyle:UIAlertControllerStyleAlert]; [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { }]; Is there any possibility to add a custom textfield inside an alert controller?

How can I use UITextField inside a CALayer?

五迷三道 提交于 2019-12-11 14:06:31
问题 I want to add a textfield inside a CALayer but I don't find a wait to do it. Code: -(void)drawInContext:(CGContextRef)ctx { NSLog(@"OK"); UITextField *field = [[UITextField alloc] initWithFrame:CGRectMake(0,120, self.frame.size.width, 100)]; [field setText:@"Test"]; [self addSublayer:field.layer]; } Any idea, suggestion, good pratices :) ? 回答1: There is no way you will manage to put a UITextField, which is a subclass of UIView, as a child (sublayer) of a CALayer, which expects an object with

UITextField shouldChangeCharactersInRange doesn't detect first character

余生颓废 提交于 2019-12-11 13:55:13
问题 I have a UITextField and I am trying to format it as phone number, however I am struggling getting the first letter of the UITextField for some reason. func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool { if textField == myTextField { var updatedTextString : NSString = PartialFormatter().formatPartial(textField.text!) self.formattedPhoneNumber(updatedTextString, textField: textField) } return true } func