Is there any disable/enable function in Xcode, i have already tried the hidden function but that really doesn't suit my needs. I'm trying to turn off my UIDatepicker if a uiswitch has been toggled and if it isn't toggled i want it shown. hiding this still outputs todays date to my mail composer. Is there anyway to do this?
Make sure you have a property (IBOutlet) for your UIDatepicker in your .h file
then you can simply do like this:
DatePickerNamed.userInteractionEnabled = YES;
DatePickerName.userInteractionEnabled = NO;
In addition to that I also turn down the alpha value for buttons and switches, if I disable them, so there is also a visual feedback that they're inactive.
Related
I often want to put my own things in the same place the keyboard pops up, but for my own controls... such as putting a UIDatePicker there, or a custom UIPickerView, or whatever.
I came up with a clumsy way of getting this behavior by having a dummy UITextField and putting my custom view in its inputView property. Then when the user clicks on my item, I just trigger off the UITextField to display the view I've assigned to the inputView.
Then I got to wondering if there was a better less kludgey way to do this. I found this article Show UIPickerView like a keyboard, without UITextField where several people recommend the same thing I do.
My question is this. Is it common to (mis)use the UITextField in this manner?
Many times you will face a UITextfield that you would want to populate through a custom control other than the standrd keyboard. Thus the inputView method was declared and can be used.
What is recommended:
1- if the UItextfield is normal, use the keybard (don't change the input view)
2- if the value is numeric, show the numberpad in keyboard directly (textField.keyboardType = .numberPad)
3- if your textField is a date then you set the input view as a date picker.
4- sometimes you need a UITextField where you need to choose between stuff. Thus you develop your own custom UIPicker and set it as an input View.
5- If what you are tring to achieve don't fall in all the above then you can do your own inputView and assign it.
So in short don't be afraid, it is the normal thing to do!
Hope this helps!
I'm working on a custom keyboard for iOS which will have its own search field (similarly implemented by PopKey).
My keyboard's textfield is able to take the focus with becomeFirstResponder and I'm able to give it up by using resignFirstResponder. However after I resign focus, the host app has a difficult time retaking focus despite touching the form. The app's textfield will still show the text cursor blinking.
Any ideas? Thanks
The solution is a hack, as of right now you can't really give the host app its focus back.
Subclass a UITextField and on its delegate implement
textFieldShouldBeginEditing by returning NO.
Add a BOOL property isSelected that gets set to YES in touchesBegan (not to be confused with the default selected property)
In your keyboard's keyPressed method, if searchField.isSelected, manipulate the searchField.text. Else, manipulate textDocumentProxy like normal.
Add a clear button and method that wipes searchField.text and searchField.isSelected, allowing any further keystrokes to return to the textDocumentProxy
Add an animation that replicates the blinking type cursor
I am trying to find a way to have UITextField appearance is distinguishable when user interaction is disabled. I have to do this application wide. Thought using UIAppearance could be an easy way to do. But couldn't figure out how to use that with user interaction enabled trait of text field.
Can you help? Or Is there an alternate way to do the same thing centrally.
Note: Text field user interaction enabled state on a given instance can get toggled based on user action.
Thanks
I don't know of an app wide way to do it if you're using text fields directly, but if you were to subclass UITextField and override setEnabled:, you could make a change to the background there.
#implementation MYTextField
- (void)setEnabled:(BOOL)enabled
{
[super setEnabled:enabled];
self.backgroundColor = [UIColor lightGrayColor];
}
#end
There is already a faint grey background for UITextFields which are disabled, but if this is not enough you can do more as above. Alternatively, you could use setDisabledBackground: on each UITextField to set an image for display when disabled - I accept that this isn't a great solution with the current design paradigms.
I've got a customized UISlider that I want to use to display information to the user with and I don't want the user to be able to interact with the slider. I've tried
mySlider.enabled = NO;
but the slider becomes greyed out, which does not look the way I want it to look.
So, how do I set a UIControl to disabled without "greying" it out.
mySlider.userInteractionEnabled = NO;
Don't you think it's going to confuse users to present an enabled slider that doesn't respond to touches? A UISlider doesn't just display information, it also tells the user that the information is user-adjustable.
You should come up with your own information display that doesn't look user-adjustable.
userInteractionEnabled probably doesn't works for the UISlider (and why it exists??) but it works for its superview. So, try attaching the UISlider to another auxiliary (transparent?) NSView and then set userInteractionEnabled = NO to this auxiliary view.
When we push on a textfield, a cursor appears in this textfield, but I don't want that this cursor appear. I want to make this textfield disabled, where you can't write inside.
How can I do this?
Can you set enabled property/userInteractionEnabled of text field to No in ViewDidLoad() using the code
textField.enabled = NO;
or
textField.userInteractionEnabled = NO;
If you're working with storyboards or .nib files and you want it to start out disabled you can also easily uncheck the enabled property in interface builder for some time-saving.