Set Buttons TitleLabel Text - uibutton

Hi all I defined a UIButton on header file and afterwards I linked it to a button in storyboard
I wrote this code in ViewDidload
[super viewDidLoad];
firstButton.titleLabel.text = #"Hello Osman";
and buttons label didnt change why ?
Sıncerely

Ok I tried what you have described in your question.
firstButton.titleLabel.text = #"Hello Osman"; // This doesn't work
[firstButton setTitle: #"Hello Osman" forState: UIControlStateNormal]; // This works

Related

Is it possible to Have a Searchbar in a UIViewController iOS 8?

I need to have a Searchbar inside a ViewController as the picture bellow. I don't wanna use UItableViewcontroller. Is it possible to have this searchbar that will help me to query in a NSMutableArray thanks to NSpredicate ?
My Goal
After Searching showing the results of the array in the View "white view".
Yes, It is possible.
You can create a search bar programmatically.
First,Add UISearchBarDelegate Protocol in .h (header) file.
#interface ViewController : UIViewController<UISearchBarDelegate>
Then, Create UISearchBar and add as subview in your view.
UISearchBar searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(30, 80, screen.size.width-60, 40)]; //give your frame x,y and width and height
searchBar.placeholder = #"Enter City Name";
searchBar.delegate = self;
//searchBar.hidden = NO;
[self.view addSubview:searchBar];
Now, Implement delegate methods
- (void)searchBarSearchButtonClicked:(UISearchBar *)aSearchBar{
//your code when search button clicked
}
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
//your code when you are entering text in search bar
}

UISwipegesturerecognizer to change ImageView positions on the view controller?

I'm an Objective-C beginner and I've found similar answers on stackoverflow to my question, but even after trying all of the tips/advice I'm still lost.
I have an IBOutlet UIImageView, and I want it to be so that if the user swipes up or down on this Image, then the position of various images on the view controller change.
I'm very green with the UISwipegesturerecognizer coding, so please explain in a way a beginner would understand. Thank you very much in advance!!!
UPDATE:
#Axeva, I used the following code, and there are no caution warnings or errors. However, it isn't executing properly on my simulator. Here is my code :
interface math0 (){
UISwipeGestureRecognizer *swipeUp;}
- (void)viewDidLoad
{
[super viewDidLoad];
swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget: self action: #selector(swipedScreenUp:)];
[swipeUp setNumberOfTouchesRequired: 1];
[swipeUp setDirection: UISwipeGestureRecognizerDirectionUp];
[one addGestureRecognizer: swipeUp];
[swipeUp setEnabled: NO];
}
- (void)swipedScreenUp:(UISwipeGestureRecognizer*)swipeGesture {
// Sampling to see if it works
instructions.text = [NSString stringWithFormat:#"IT WORKED!"];
}
In my .h file, I declared - (void)swipedScreenUp:(UISwipeGestureRecognizer)swipeUp;. On my storyboard, I set my image (named one) so that it was accessibility and user interaction enabled.
I've also tried with [swipeUp setEnabled: YES]; in my viewDidLoad file.
Can you or anyone tell me where the error is? Thank you!!
Try something like this:
#interface YourViewController () {
UISwipeGestureRecognizer *swipeLeftToRightGesture;
}
- (void)viewDidLoad {
[super viewDidLoad];
swipeLeftToRightGesture = [[UISwipeGestureRecognizer alloc] initWithTarget: self action: #selector(swipedScreenRight:)];
[swipeLeftToRightGesture setNumberOfTouchesRequired: 1];
[swipeLeftToRightGesture setDirection: UISwipeGestureRecognizerDirectionRight];
[[self view] addGestureRecognizer: swipeLeftToRightGesture];
}
- (void)swipedScreenRight:(UISwipeGestureRecognizer*)swipeGesture {
// Move your image views as desired
}
You can adjust this basic code to do exactly what you wish. (different swipe directions; etc.)

Some time cannot hide iOS keyboard and show UIPickerView

This is my .h
xxxx : UIViewController<UITextFieldDelegate>
and my .m
UITextField *quarterPicker = [[[UITextField alloc] init] autorelease];
[quarterPicker setFrame:CGRectMake(150, 370, 60, 30)];
[quarterPicker setText: #"Q1"];
quarterPicker.delegate = self;
and i use
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
NSLog(#"textFieldShouldBeginEditing");
[textField resignFirstResponder];
[textField addTarget:self action:#selector(selectQuarterPicker:) forControlEvents:UIControlEventTouchDown];
return NO; // Hide both keyboard and blinking cursor.
}
When i touch to my textField, i alway see this log textFieldShouldBeginEditing
But some time, my Picker doesn't show. I use : https://github.com/TimCinel/ActionSheetPicker to make Picker.
I find out that, when i swipe my textFiled, my picker will display.
How can i fix this?
UPDATE: i put my UITextFiled insite UIScrollView
You are adding the target for the touch event after the first touch is made. So only the second will work. Why add this event? You can simply show the picker inside shouldBeginEditing without adding a touch event
Something like
[self selectQuarterPicker:self]; //assuming the parameter is the sender as you commented

Why is my image not being passed to my ViewController?

I have my app set up so that there will be multiple image pickers, each with it's own array of images. The user will press which set they wish to view, select an image, and then the app will pop back to the Root Controller. I want the image they have selected to be added as a SubView to my main ViewController.
I'm having issues getting the main ViewController to detect the image selected though.
Here's how I am trying:
In my Image Picker:
EDIT I'm having an issue again. I have added a new viewController so the users will choose which set of array of images they want to see instead of going straight to the array of images. I changed the way I pop to the viewController since I am not going back to the RootViewController now.
- (IBAction)buttonClicked:(id)sender
{
UIButton *button = (UIButton *)sender;
_selectedImage = [_images objectAtIndex:button.tag];
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
delegate.viewController.stampedImage = _selectedImage;
NSLog(#"delegate.viewController = %#", delegate.viewController);
NSLog(#"delegate.viewController.stampedImage = %#", delegate.viewController.stampedImage);
NSLog(#"_selectedImage = %#", _selectedImage);
[delegate.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
}
I've ran an NSLog here and the selectedImage is set to an image.
Here is what I am doing in my main ViewController where I want the image to appear. I am running this code in viewWillAppear:
//stampedImage = _imagePicker.selectedImage; --- Not sure if I need this line
_stampedImageView = [[UIImageView alloc] initWithImage:stampedImage];
NSLog(#"ViewController stampedImage = %#", stampedImage);
[_stampedImageView setFrame:CGRectMake(0, 0, 80.0, 80.0)];
[_stampedImageView setMultipleTouchEnabled:YES];
[_stampedImageView setUserInteractionEnabled:YES];
[imageView addSubview:_stampedImageView];
[_stampedImageView release];
I've ran an NSLog here but the stampedImage always returns as null.
The stampedImage is always coming back as null
I have the stampedImage set as a property and is being synthesized.
I have also set done an #class in the .h for my image picker class.
Any ideas? I'm stumped on this one for some reason.

Adding tool bar on top of the uikeyboard

I have a toolbar and i would like to place it on top of the keyboard.
In the keyboardwillshow notification, i tried to add toolbar to the keyboard but no luck, i cant add
Please let me know
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i = 0; i < [tempWindow.subviews count]; i++)
{
//Get a reference of the current view
keyboard = [tempWindow.subviews objectAtIndex:i];
//Check to see if the description of the view we have referenced is "UIKeyboard" if so then we found
//the keyboard view that we were looking for
if([[keyboard description] hasPrefix:#"<UIKeyboard"] == YES)
{
[keyboard addSubview:myToolbar];
}
}
I think, you want an inputAccessoryView.
Basically, you create a view and set it as a text field's or text view's input accessory view.
[textField setInputAccessoryView:inputAccessoryView];
Here is code in case someone else need it.Found on stack overflow
- (void)viewDidLoad
{
[super viewDidLoad];
UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
numberToolbar.barStyle = UIBarStyleBlackTranslucent;
numberToolbar.items = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithTitle:#"Clear" style:UIBarButtonItemStyleBordered target:self action:#selector(clearNumberPad)],
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc]initWithTitle:#"Apply" style:UIBarButtonItemStyleDone target:self action:#selector(doneWithNumberPad)],
nil];
[numberToolbar sizeToFit];
numberTextField.inputAccessoryView = numberToolbar;
}
-(void)clearNumberPad{
[numberTextField resignFirstResponder];
numberTextField.text = #"";
}
-(void)doneWithNumberPad{
NSString *numberFromTheKeyboard = numberTextField.text;
[numberTextField resignFirstResponder];
}
https://github.com/asefnoor/IQKeyboardManager
This is the best keyboard handler I have seen. Very excellent way to manage Text inputs.
Some of its features 1) ZERO LINE OF CODE
2) Works Automatically
3) No More UIScrollView
4) No More Subclasses
5) No More Manual Work
6) No More #imports
Simple solution for iOS 8 and 9.
Init your textField, searchBar etc.
customView - View that will stick at the top of the keyboard. DO not add it as a subview to hierarchy! Do not have to set any constraints or positions.
[searchBar setInputAccessoryView:self.customView];
- (BOOL)canBecomeFirstResponder{
return true;
}
- (UIView *)inputAccessoryView {
return self.customView;
}
If you need to let the customView at the bottom and not hide it after dismissing keyboard, add observer:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:self.view.window];
And method
- (void)keyboardDidHide:(NSNotification *)notification {
[self becomeFirstResponder];
}
if you want to add tool bar on the keyboard, you are right place. You can use BSKeyboard easly. Look at the implementation below;
in .h file
#import "BSKeyboardControls.h"
add delegates
#interface ViewController : UIViewController <BSKeyboardControlsDelegate>
now jump the .m file , go to viewDidLoad. We will add textfield which i want to add tollbar
self.keyboardControls = [[BSKeyboardControls alloc] initWithFields:#[PINTextField]];
[self.keyboardControls addDelegate:self];
we should add activeField just like below,
- (void)textFieldDidBeginEditing:(UIView *)textField {
[self.keyboardControls setActiveField:textField];
}
And last step is delegate metods implemantation,
- (void)keyboardControlsDonePressed:(BSKeyboardControls *)keyboardControls {
[super textFieldShouldReturn:self.keyboardControls.activeField];
}
That's it.
For more info and download the BSKeyboard files, you can move the below link BSKeyboard Githup Link