How to set a default Value of a UIPickerView

TL:DR version: //Objective-C [self.picker selectRow:2 inComponent:0 animated:YES]; //Swift picker.selectRow(2, inComponent:0, animated:true) Either you didn’t set your picker to select the row (which you say you seem to have done but anyhow): – (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated OR you didn’t use the the following method to get the selected item from your picker – (NSInteger)selectedRowInComponent:(NSInteger)component This will … Read more

Add image to UITextField in Xcode?

UITextField has a rightView property, if you have image like this- then You can easly set ImageView object to rightView: UITextField *myTextField = [[UITextField alloc] init]; myTextField.rightViewMode = UITextFieldViewModeAlways; myTextField.rightView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@”downArrow.png”]];

How to make an UIPickerView with a Done button?

Add this code to your viewDidLoad() instead of method let picker: UIPickerView picker = UIPickerView(frame: CGRectMake(0, 200, view.frame.width, 300)) picker.backgroundColor = .whiteColor() picker.showsSelectionIndicator = true picker.delegate = self picker.dataSource = self let toolBar = UIToolbar() toolBar.barStyle = UIBarStyle.default toolBar.isTranslucent = true toolBar.tintColor = UIColor(red: 76/255, green: 217/255, blue: 100/255, alpha: 1) toolBar.sizeToFit() let doneButton = … Read more

How to disable UITextField editing but still accept touch?

Using the textfield delegate, there’s a method – (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string Return NO from this, and any attempt by the user to edit the text will be rejected. That way you can leave the field enabled but still prevent people pasting text into it.

How to change UIPickerView height

It seems obvious that Apple doesn’t particularly invite mucking with the default height of the UIPickerView, but I have found that you can achieve a change in the height of the view by taking complete control and passing a desired frame size at creation time, e.g: smallerPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 120.0)]; You … Read more

How do I change the color of the text in a UIPickerView under iOS 7?

There is a function in the delegate method that is more elegant: Objective-C: – (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component { NSString *title = @”sample title”; NSAttributedString *attString = [[NSAttributedString alloc] initWithString:title attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}]; return attString; } If you want to change the selection bar colors as well, I found that I had to add 2 … Read more

Add UIPickerView & a Button in Action sheet – How?

One more solution: no toolbar but a segmented control (eyecandy) UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent]; CGRect pickerFrame = CGRectMake(0, 40, 0, 0); UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame]; pickerView.showsSelectionIndicator = YES; pickerView.dataSource = self; pickerView.delegate = self; [actionSheet addSubview:pickerView]; [pickerView release]; UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@”Close”]]; … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)