I have small view with a UITextField in it. I want to make the view hidden by default. when a button clicked it should show the view and the elements in main view below this sub view must be scrolled down. Any idea? I'm attaching the screenshots
Set the UITextView as hidden from InterfaceBuilder (you can set it from code too).
After this attach this action handler to the UIButton.
- (IBAction)showTextBar
{
[textView setHidden:False];
return;
}
This will show the textBar. If you want to show some other elements then you can add them in this method. Also you can make this method like a toggle. click once to show the elements, click again to hide them.
Inside the action u can also use
textView.hidden = NO;
As for the scrolling use a UIScrollView something like
[_scrollView setContentOffset:CGPointMake(0,_textView.center.y+168) animated:YES];
//Alternate between hide and show when button is clicked
-(IBAction)showTextBar
{
if(textview.hidden)
{
[textView setHidden:False];
}
else
{
[textView setHidden:True];
}
}
Related
I am making an tab bar application. I want to disable one tab bar button which I am able to make through the code
[[[[[self tabBarController] viewControllers] objectAtIndex:2] tabBarItem] setEnabled:FALSE];
But the image gets disabled. I want the image to be enabled. How it can be possible without using the custom image through code. I do not want to use the custom image of tab bar buttons. I want to use default selected and non selected tab bar button images.Please suggest.
Thanks in advance.
You can try the following: to switch the UIBarButtonItem to disabled, instead of switching the property, change tintColor property to a clear color. This will prevent the button from being tinted when tapped. Then, in the delegate, check if the button is disabled and return if so:
// inside view controller .m
-(void)disableButton
{
[barBtn setTintColor:[UIColor clearColor]];
}
-(void)enableButton
{
[barBtn setTintColor:[UIColor grayColor]]; // whatever color the tint should be
}
-(void)buttonTapped:(id)sender
{
if ([barBtn tintColor] == [UIColor clearColor])
{
return; // button is disabled, so don't to action
}
}
I have a uiview with a button on that. When click on that button i am showing a subview.
The subview contains a table view and a search display controller. when i enter something on search bar it will be showing the search result tableview.
once search is done and going back to the superview and again come back to subview, the table view that displays all the records is not scrollable and also the search bar contains the text that has been entered before, that is search bar contains text but the tableview is not search result table view.
This issue will not come if i click on Cancel button of searchbar, without clicking on cancel button if i go back to superview, the issue arises.
When you show yourTableview with searchBar at that time set bellow code..
searching = NO; // if you use this BOOL value..
and also clear the text of UISearchBar's text i.e.
searchBar.text = #"";
and after reloadData of UITableView
-(void)showSearchTable // its an example
{
searching = NO;
searchBar.text = #"";
[yourTableView reloadData];
}
Is there any way to hide or do not show the keyboard without calling resignFirstResponder in iOS? I know different method to hide keyboard, first one is to make the textview non editable, or using
- (BOOL)textFieldShouldEndEditing:(UITextView *)textview
{
[textview resignFirstResponder];
}
but in my case these method will not be works out, becz I just want to dismiss or hide the keyboard only, but need the editing in textview. I have a textview which contains some text, when I tap the sentence it need to be selected, I have done that selection part nicely, but when I write above keyboard dismissal method in my project, the selection of the tapped sentence doesn't appear,.is there any method to o this.
Textfield's selection will remain only when you are in editing mode. When you resign your first responder your selection disappears too.
To avoid bringing keypad in editing mode, you can change the input view. For example , look at the code,
textview.inputView = [[UIView alloc] init];
This brings a custom input view and it is not visible.
Add
self.textView.editable = NO;
Try this
NSRange selection = [yourTextView.text rangeOfString:yourTextView.text];
if( selection.location != NSNotFound ){ yourTextView.selectedRange = selection; }
It will remove the keyboard from the textview. Hope it helps.
In My view there is reset button .i need userinteraction disabled except for that button .how can i do that can any one share the code.thanks in advance?
btn1 is your button, self.view - your view
for (UIView *view in self.view.subviews)
view.userInteractionEnabled=NO;
btn1.userInteractionEnabled=YES;
For all the elements there is a property userinteractionenabled. Set it to false
yourelement.userInteractionEnabled = NO;
Also place your UIButton on top of your view hierachy.
Other option is to place a tranparent UIButton on your entire view and your UIButton on top of this view. This way only your UIButton is touch enalbed. Other touches would be taken in by the transparent button which does nothing.
Sligthly better approach, define a "magic value" that will help you :
#define kDontDisableUserInteraction 3928473
then set this value as the tag of your button you don't want disabled:
[resetButton setTag:kDontDisableUserInteraction];
you can now create a function in your superview's class :
- (void)setInterfaceEnabled:(BOOL)newEnabled {
for (UIView *subview in self.subviews) {
if (subView.tag != kDontDisableUserInteraction)
continue;
subView.userInteractionEnabled = newEnabled;
}
}
That allows you to create other non-disableable buttons simply by giving them the right tag (which can be whatever int value you want, not only 3928473, depends on your #define).
Imagine I have a UIView and to that I add 2 UIButtons.
I find that I can put a finger on one button, then, holding the first, I can touch the 2nd button with another finger. Both buttons will show their UIControlStateHighlighted images.
Is there a way to stop the 2nd touch working? I thought that multipleTouchEnabled = NO was the answer, but seems not!
Any ideas?
use a property of UIButton called exclusiveTouch
-(IBAction)button1Pressed {
button2.enabled = NO;
}
-(IBAction)button2Pressed {
button1.enabled = NO;
}
For touch down.
Then for touch up inside and touch up outside.
-(IBAction)button1Lifted {
button2.enabled = YES;
}
-(IBAction)button1Lifted {
button2.enabled = YES;
}
when you tab on 1st button, in Button's IBAction method,make a user interaction of a 2nd button disabled.(On 1st line)
and in last line of 1st button IBAction code, make 2nd button user interaction enabled.(on last line). set IBAction to touchDown.
& vice-versa.
add this property to each button\n
button.exclusiveTouch=YES;