uitextfield

UITextField rightView “WhileEditing” problem

旧街凉风 提交于 2019-11-30 20:36:50
I try to subclass UITextField as follows to implement custom rightView as a Clear button: -(void) drawRect:(CGRect)rect { [self.layer setBackgroundColor:[[UIColor colorWithRed:20.0/255.0 green:20.0/255.0 blue:20.0/255.0 alpha:1] CGColor]]; [self.layer setCornerRadius:15.0]; UIImage *imgClear = [UIImage imageNamed:@"btnClear"]; CGSize iSize = [imgClear size]; UIButton *clearButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, iSize.width, iSize.height)]; [clearButton setImage:imgClear forState:UIControlStateNormal]; [clearButton addTarget:self action:@selector(clearText:) forControlEvents

how to make designable textfield code class in swift

断了今生、忘了曾经 提交于 2019-11-30 20:36:10
问题 I am a beginner in programming and in iOS development. I want to make a swift file that contains a code to make Designable textfield, so I will not edit the UI element display by coding, all the UI that will be edited, I will edit it in Interface builder. I need to input an image in UITextfield, and I follow along a tutorial in here https://www.youtube.com/watch?v=PjXOUd4hI6U&t=932s to put an image in the left side of the UITextField, like the lock image in the picture above. here is the the

Resize UITextField horizontally with text using Auto Layout

对着背影说爱祢 提交于 2019-11-30 19:35:51
An example project to demonstrate the below issue can be found here: https://github.com/markdorison/UITextFieldContentSizeExample/ I am attempting to have a UITextField grow/shrink its width with the text content it contains using Auto Layout. I have created leading and trailing constraints with a priority of 749 (as opposed to the default: 1000). I have also tried lowering the priority of these constraints all the way down to 1, but this does not seem to have a noticeable effect on the behavior. By listening to the UIControlEventEditingChanged event, I am triggering a reset of the

UITextField should have only positive number

被刻印的时光 ゝ 提交于 2019-11-30 19:20:19
问题 I need to validate a UITextField . I want only positive integers to be entered in it. How can I achieve that? 回答1: Add UITextFieldDelegate,and add this code to your class #define LEAGELNUM @"0123456789" - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:LEAGELNUM] invertedSet]; NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs

UITextField changes font while editing

筅森魡賤 提交于 2019-11-30 19:17:52
I am suffering the same problem as here UITextField's custom font changes while in edit mode and could really do with a solution. I have 4 UITextFields that I assign custom fonts in ViewDidLoad. This works and they look great, however when clicking a field to edit the text the font changes back to default text and when resignedfirstresponder the custom font comes back. - (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

UITextField with a dropdown menu for iPhone

允我心安 提交于 2019-11-30 18:28:03
问题 Is there an easy way to create a drop down menu for a UITextField, so that the user can type a custom entry or select one from a list? 回答1: For drop down menu you can implement UITableView. You can populate this UItableview with your list. Just declare it in ViewDidLoad method of your ViewController and then you can show or hid accordingly later. TableView = [[UITableView alloc]initWithFrame:CGRectMake(x,x,x,x) ]; TableView.delegate = self; TableView.dataSource = self; Add this to main view

Storing UITextField contents before view pops

痴心易碎 提交于 2019-11-30 18:20:35
I am sure this is in the Apple documentation or must have been answered somewhere on this forum, since it seems so basic, but I could not find it nor a particularly elegant solution myself. What I have is a UIViewController that pushes an editing view on its navigation stack. The editing view has a bunch of UITextFields in it. If one of them is being editing when the back button is touched, the original view's ViewWillAppear method is called before either the UITextField delegate methods of textFieldShouldEndEditing or textFieldDidEndEditing , or the IB linked action textFieldEditingEnded

Why doesn't dismissWithClickedButtonIndex ever call clickedButtonAtIndex?

别来无恙 提交于 2019-11-30 17:41:38
http://iphonedevelopment.blogspot.com/2009/02/alert-view-with-prompt.html I'm using that code to get my iPhone app to display an alertView with an included UITextField and matching CANCEL and OK buttons. The user can enter text, hit CANCEL or OK... and I see the text the user entered... using my code inside the clickedButtonAtIndex method. It all works except for 1 thing: Instead of OK, the user might hit DONE on the keyboard. I'm using dismissWithClickedButtonIndex to simulate an OK click... but then clickedButtonAtIndex never gets called. Shouldn't dismissWithClickedButtonIndex also call

How to center UITextField text in Swift

寵の児 提交于 2019-11-30 17:09:45
I have a UITextField object with the text property set to "hi". However these two lines have no affect on where "hi" is located myUITextObject.contentVerticalAlignment = UIControlContentVerticalAlignment.Center myUITextObject.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Center Is this a bug in Swift? If so how do I go about logging this as a bug so Apple can fix it in the next Swift release? Dave Wood You would want to write it like this: myUITextObject.textAlignment = .center (Edited to change from .Center to .center) What you're looking for is the textAlignment property;

Resize UITextField horizontally with text using Auto Layout

坚强是说给别人听的谎言 提交于 2019-11-30 16:55:26
问题 An example project to demonstrate the below issue can be found here: https://github.com/markdorison/UITextFieldContentSizeExample/ I am attempting to have a UITextField grow/shrink its width with the text content it contains using Auto Layout. I have created leading and trailing constraints with a priority of 749 (as opposed to the default: 1000). I have also tried lowering the priority of these constraints all the way down to 1, but this does not seem to have a noticeable effect on the