uitextfield

How to vertically align a UILabel used as a leftView in a UITextField with the textField's text?

陌路散爱 提交于 2019-12-07 07:07:16
问题 I'm using a UILabel as the leftView of a UITextField . The issue is that the textField's text is higher than the label's. This is the code I've used so far UILabel *startsWith = [[UILabel alloc] init]; startsWith.font = [UIFont systemFontOfSize:14]; startsWith.textColor = [UIColor blackColor]; startsWith.backgroundColor = [UIColor clearColor]; startsWith.text = @"Text"; [startsWith sizeToFit]; self.textField.leftViewMode = UITextFieldViewModeAlways; self.textField.leftView = startsWith; I've

Invalid context 0x0 on UITextField (Xcode 5)

廉价感情. 提交于 2019-12-07 05:55:46
问题 I am using a UITextField in my app. I am using [texfield becomeFirstResponder] . This works just fine and loads the keyboard when the view is loaded. However, this error comes up when I click on the UITextField again after it has been brought up. I don't understand exactly why, but here is the output I am getting: CGContextSetFillColorWithColor: invalid context 0x0. CGContextSetStrokeColorWithColor: invalid context 0x0. CGContextSaveGState: invalid context 0x0. CGContextSetFlatness: invalid

Why doesn't the clear button aligned with the text in a UITextField?

人走茶凉 提交于 2019-12-07 05:26:55
问题 I have an UITextField in an UITableViewCell. For some reason the clear button isn't align to the textField's text. Here's my textField code: cell.selectionStyle = UITableViewCellSelectionStyleNone; usernameField = [[UITextField alloc] initWithFrame:CGRectMake(22, 10, cell.contentView.frame.size.width, cell.contentView.frame.size.height)]; usernameField.adjustsFontSizeToFitWidth = YES; usernameField.placeholder = @"Username"; usernameField.backgroundColor = [UIColor clearColor]; usernameField

Dotted / Dashed border for UITextView / UITextField

本秂侑毒 提交于 2019-12-07 05:19:40
问题 I want to set a Dotted / Dashed border for my UITextField and UITextView . How can I do that? I know that, I can set border with this line of code: [self.textFieldCardTitle.layer setBorderWidth:1.0]; [self.textFieldCardTitle.layer setBorderColor:[[UIColor whiteColor] CGColor]]; Notice: I already have the idea to add a UIImageView behind the UITextView and set there an image with dashed border. But I don't want to solve it that way. 回答1: You could try, for example, next approach: 1) Create

How to hide Toolbar in IQKeyboardManager iOS Swift 3

不羁岁月 提交于 2019-12-07 04:49:42
问题 I'm using the IQKeyboardManger library to scroll text fields when started typing using the keyboard, but I don't want to display the default toolbar from their library. Below is the code I've used. override func viewDidLoad() { super.viewDidLoad() self.chatTextField.inputAccessoryView = [[UIView alloc] init]; //This will remove toolbar which have done button. self.chatTextField.keyboardDistanceFromTextField = 8; //This will modify default distance between textField and keyboard. For exact

UITextfield borderColor and width on one side of the text field

。_饼干妹妹 提交于 2019-12-07 04:20:45
问题 I have a text field setup like so: textField.borderStyle = UITextBorderStyleLine; textField.layer.borderColor = [[UIColor greenColor] CGColor]; textField.layer.borderWidth= 10.0f;' But is it possible to just have a larger border on the left side and it be a different color? Or do I have to position a drawRect there with the color I want and position? 回答1: try with this code might be help's you add Border left side of custom TextFiled like Bellow:- - (void)viewDidLoad { [super viewDidLoad];

Detect UISearchBar focus on the text field

纵饮孤独 提交于 2019-12-07 03:52:12
问题 Is there a way to detect if a user has click on the searchbar textfield and the keyboard has appear ? 回答1: From the docs, searchBarTextDidBeginEditing: searchBarCancelButtonClicked: 回答2: If you are implementing UISearchBarDelegate, the first method that should be called is: - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar { //do stuff return YES; } Here's the class reference: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UISearchBarDelegate_Protocol

Using NSNumberFormatter to format currency in output UILabel

好久不见. 提交于 2019-12-07 03:13:22
问题 NSNumberFormatter * fmt; NSNumber * n; fmt = [ [ NSNumberFormatter alloc ] init ]; n = [ NSNumber numberWithFloat: 10 ]; [ fmt setFormatterBehavior: NSNumberFormatterBehavior10_4 ]; [ fmt setCurrencySymbol: @"$" ]; [ fmt setNumberStyle: NSNumberFormatterCurrencyStyle ]; // NSLog( @"%@", [ fmt stringFromNumber: n ]; [ fmt release ] -(IBAction)buttonPressed1:(id)sender { double currency = [Amount1.text doubleValue] + [Amount2.text doubleValue]; SumCurrency.text = [NSString stringWithFormat:@"%0

Animating UITextInput's textInputView

流过昼夜 提交于 2019-12-07 03:04:14
问题 UIKit text input components, such as UITextView and UITextField have a property inputView to add a custom keyboard. There are two questions I have relating to this. If the keyboard is currently visible and the property is set to a new input view, nothing happens. Resigning and regaining first responder status refreshes the input and displays the new view. Is this the best way to do it? If so it might answer my bigger question: Is it possible to animate the transition between two input views?

UITextPosition to Int

不想你离开。 提交于 2019-12-07 02:46:50
问题 I have a UISearchBar on which I am trying to set a cursor position. I am using UITectField delegates as I couldn't find anything direct for UISearchBar. Below is the code I am using: UITextField *textField = [searchBar valueForKey: @"_searchField"]; // Get current selected range , this example assumes is an insertion point or empty selection UITextRange *selectedRange = [textField selectedTextRange]; // Construct a new range using the object that adopts the UITextInput, our textfield