iOS 7 UIBarButtonItem with accessibility - ios

Im trying to give my barbuttonitem in the navigationBar a value that the VoiceOver can read, instead of reading the imgname.
I tried this, but it doesn't work:
self.barBtnAbout.accessibilityLabel = NSLocalizedString(#"about", nil);
self.barBtnAbout.accessibilityHint = NSLocalizedString(#"about", nil);
Any bright ideas?
Kind Regards!

I have done this using the following:
UIView *view = (UIView*)self.navigationItem.leftBarButtonItem;
[view setIsAccessibilityElement:YES];
[view setAccessibilityLabel:NSLocalizedString(#"about", #"")];
[view setAccessibilityHint:NSLocalizedString(#"about", #"")];

The correct way to setup basic accessibility for a UIBarButtonItem is like this:
myBarButtonItem.isAccessibilityElement = YES;
myBarButtonItem.accessibilityLabel = NSLocalizedString(#"a short description",#"")];
myBarButtonItem.accessibilityTraits = UIAccessibilityTraitButton;

Related

CGRectMake doesn't work

I'm working on example from "iOS Programming Cookbook", based on iOS 7. I need to create UITextField and add it to ViewController.
In ViewController.m I have:
- (void) viewDidLoad {
[super viewDidLoad];
[self createField];
}
- (void) createField {
self.textField = [[UITextField alloc] initWithFrame:CGRectMake(20.0f, 35.0f, 280.0f, 30.0f)];
self.textField.translatesAutoresizingMaskIntoConstraints = NO;
self.textField.borderStyle = UITextBorderStyleRoundedRect;
self.textField.placeholder = #"Enter text to share";
self.textField.delegate = self;
[self.view addSubview:self.textField];
}
On screenshot from book textField appears in the middle of screen's width under the status bar, but when I run it textField appears on the top left corner of screen behind the status bar.
Maybe the problem is, that I run app on iPhone 6 simulator with iOS 8. But I don't know how to solve it.
Thanks!
Using self.textField.translatesAutoresizingMaskIntoConstraints = NO; is pretty much telling the object that it doesn't really care about the frame but relies more on the constraints that you give it. Setting it to YES takes the frame and automatically applies constraints to it to mimic the frame that you give it.
For example it would apply the constraints to have the frame appear at: CGRectMake(20.0f, 35.0f, 280.0f, 30.0f). When setting it to NO use NSLayoutConstraint and create the constraints programatically.
But in your case just remove the line
self.textField.translatesAutoresizingMaskIntoConstraints = NO;
because it is set to YES by default.

Cannot set UISearchBar's translucent property to NO

I am trying to set the barTintColor of a UISearchBar without translucency. However, setting the translucent property doesn't seem to do anything. I have reproduced the issue in a bare-bones Xcode project here.
self.searchDisplayController.searchBar.translucent = NO;
self.searchDisplayController.searchBar.barTintColor = [UIColor redColor];
The red color above is not the same as [UIColor redColor] in UIViews that are not translucent. I know about the workaround involving setting a background image on the search bar, but the above code should work as well.
I downloaded your code and find solution for, add one method name is removeUISearchBarBackgroundInViewHierarchy and set searchBar.backgroundColor as redColor.
- (void)viewDidLoad
{
[super viewDidLoad];
self.searchDisplayController.searchBar.translucent = NO;
[self removeUISearchBarBackgroundInViewHierarchy:self.searchDisplayController.searchBar];
self.searchDisplayController.searchBar.backgroundColor = [UIColor redColor];
}
- (void) removeUISearchBarBackgroundInViewHierarchy:(UIView *)view
{
for (UIView *subview in [view subviews]) {
if ([subview isKindOfClass:NSClassFromString(#"UISearchBarBackground")]) {
[subview removeFromSuperview];
break; //To avoid an extra loop as there is only one UISearchBarBackground
} else {
[self removeUISearchBarBackgroundInViewHierarchy:subview];
}
}
}
Please set image in search bar like this it will solve your problem.
[[UISearchBar appearance] setBackgroundImage:[UIImage imageNamed:#"red"]];
Thanks.
Maybe too late for the party,
However I've done a very simple and nifty extension for Swift 3 that allows you to use the translucent property without any trouble.
It involves no use of private API or dangerous walk-through within the object.
You can download it from this Github repository.

Cannot make programmatically created UITextField editable (iOS)

I created a UITextField programatically, (I do not use storyboard) and added it as a subview to ViewController with this code:
#interface ViewController ()
#property (nonatomic, strong) UITextField *searchLocationBar;
#end
...
#synthesize searchLocationBar;
...
self.searchLocationBar = [[UITextField alloc] init];
self.searchLocationBar.frame = CGRectMake(0.0f, 0.0f, 320.0f, 40.0f);
self.searchLocationBar.delegate = self;
self.searchLocationBar.borderStyle = UITextBorderStyleRoundedRect;
self.searchLocationBar.placeholder = #"a temporary placeholder";
self.searchLocationBar.userInteractionEnabled = YES;
self.searchLocationBar.clearButtonMode = UITextFieldViewModeAlways;
[self.view addSubview:self.searchLocationBar];
However, I cannot enter any text - nothing happens, when I tap on a textfield. It's not overlapped by any other view.
I've checked UITextfield not editable-iphone but no effect
I'm newbie and totally sure I simply miss something - please advice.
Thanks!
EDIT:
One more thing: I have a Google Maps GMSMapView assigned to self.view as
self.view = mapView_; as written in Google API documentation.
After some tests I found that with this declaration all controls work perfectly, but not textfields. I would prefer not to move a map view to any subview as I will need to rewrite lots of things.
Can someone please add any suggestions?
you forget add:
[self.view bringSubviewToFront:self.searchLocationBar];
In Xcode 5 your code should work.Better you check your Xcode version.May be the problem with your code with Xcode versions.You can try by following way.
UITextField *lastName = [[[UITextField alloc] initWithFrame:CGRectMake(10, 100, 300, 30)];
[self.view addSubview:lastName];
lastName.placeholder = #"Enter your last name here"; //for place holder
lastName.textAlignment = UITextAlignmentLeft; //for text Alignment
lastName.font = [UIFont fontWithName:#"MarkerFelt-Thin" size:14.0]; // text font
lastName.adjustsFontSizeToFitWidth = YES; //adjust the font size to fit width.
lastName.textColor = [UIColor greenColor]; //text color
lastName.keyboardType = UIKeyboardTypeAlphabet; //keyboard type of ur choice
lastName.returnKeyType = UIReturnKeyDone; //returnKey type for keyboard
lastName.clearButtonMode = UITextFieldViewModeWhileEditing;//for clear button on right side
lastName.delegate = self; //use this when ur using Delegate methods of UITextField
There are lot other attributes available but these are few which we use it frequently.if u wanna know about more attributes and how to use them refer to the following link.
You can also make property for UITextField.Either way should work fine in Xcode.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextField_Class/Reference/UITextField.html

Popup displaying image on iPhone app?

I want to show an image in popup view which also contains the close button.
I have searched for that but I did not found any thing about that.
Please help me??
Just try out following simple way -
You can create one UIView that contains UIImageView and UIButton.
Whenever you want to show the the image just assign image to the UIImageView and and show the UIView.
And when you want to hide the the image just hide the UIView on pressing UIButton (i.e close button).
Hope this will help you.
try this for popup
1) ALPopup
2) BlureModelView
3) Ogactionchooser
4) Other and This
- (IBAction)btn:(id)sender {
UIView *contentView;
UIImageView *dot;
contentView = [[UIView alloc] initWithFrame:CGRectMake(0,0,300,350)];
contentView.backgroundColor = [UIColor whiteColor];
contentView.layer.cornerRadius = 5.0;
dot =[[UIImageView alloc] initWithFrame:CGRectMake(50,40,200,200)];
dot.image = [UIImage imageNamed:"DSC_0055.JPG.jpg"];
dot.contentMode = UIViewContentModeScaleAspectFit;
[contentView addSubview: dot];
[[KGModal sharedInstance] showWithContentView:contentView andAnimated:YES];
}
}
https://github.com/kgn/KGModal

A UIButton above a UIPickerView

I have a UIPickerView which works correctly, now I want to add a button above it so that I can dismiss it.
and here is my code where I initiate a UIPickerView as well as its dismiss button:
- (UIPickerView *)creatPickerView {
UIPickerView *tempPickerView = [[[UIPickerView alloc]
initWithFrame:CGRectMake(kPickerViewX, kPickerViewY, kPickerViewWidth, kPickerViewHeight)] autorelease];
tempPickerView.showsSelectionIndicator = YES;
tempPickerView.delegate = self;
tempPickerView.dataSource = self;
UIButton *pickerButton = [[UIButton alloc] initWithFrame:CGRectMake(270, -32, 50, 32)];
[pickerButton setBackgroundImage:[UIImage imageNamed:#"hidePicker.png"]
forState:UIControlStateNormal];
[pickerButton addTarget:self action:#selector(hidePicker)
forControlEvents:UIControlEventTouchUpInside];
[tempPickerView addSubview:pickerButton];
[pickerButton release];
[self.view addSubview:tempPickerView];
return tempPickerView;
}
and it works well on my iPhone 4.3 Simulator, like this:
apparently there is a button on the upper right of the pickerView,
problem is, when I run the app in my device - a 5.0.1 iPhone4 and a 4.2.1 iTouch, the button is missed like it has never been added to the pickerView.
Can anyone help me with this?
Thanks a lot and a lot!
I found the reason, it seems the png has some problem,
after I change another png, it comes up in the screen!
but the real problem is that I place the button outside of the pickerView which results in the button's untouchableness.
But anyway the pickure is only a small problem.

Resources