Set accessibility badge on a tabbarItem - iphone

I have a tabbar application. If there is a badge on a certain tab VoiceOver pronounces N items. I'd like to make it pronounce N messages.
How do I do that?

I had a similar problem,
it seems that UITabBarViewController.tabbar is handling accessibility differently than other views.
So my solution was placing another uiview above the badge as a subview of [tabbar superview] and adding accessibility to this view:
At viewDidLoad:
self.badgeAccessibilityView = [[UIView alloc] init];
//use tabBarView.frame to calculate
self.badgeAccessibilityView.frame = frameAccordingToBadgeLocation;
self.badgeAccessibilityView.userInteractionEnabled = YES;
self.badgeAccessibilityView.isAccessibilityElement = YES;
[self.tabBarView.superview addSubview:self.badgeAccessibilityView];
On badge value change:
self.badgeAccessibilityView.accessibilityLabel =
[NSString stringWithFormat:#"%d Notifications", badgeValue];

Related

How to customise the iOS badge number background

How can I customise the badge number on UITabBarItem?
Something like this
Have a Look at MKNumberBadgeView. Its a little Class for your Custom BadgeView.
Using it like this I am able to add it to my custom UITabBarController:
MKNumberBadgeView *badge = [[MKNumberBadgeView alloc] initWithFrame:CGRectMake(110, self.view.frame.size.height-20, 30, 30)];
badge.value = 12;
UIWindow *window = [[UIApplication sharedApplication].windows objectAtIndex:0];
[[[window subviews] objectAtIndex:0] addSubview:badge];
Wich will look like this:
Of course you have to take care of rotating issues when adding the badgeView to the window.
But I guess you can customize MKNumberBadgeView to make it look the way you want it, give it a try.

How to set uitextfield to italics Xcode 4.5

I have an app where the users enters information in a few textfields which are then added to a uitextview by a nsstring does anybody know how i can set one of the textfields to italics and keep the others normal
regards
Edit:
Heres my code i want to only change once textfield (e.g textfbookpublisher):
NSString* combinedString = [NSString stringWithFormat:
#"%#,%#.'%#.'%#.%#,%#.",
textfbookpublisher.text,
textfbookauthor.text,
textfbooktitle.text,
textfbookplace.text,
nameofuni.text,
textfbookyear.text];
DissertationGen*bookg = [[DissertationGen alloc] init];
bookg.message = combinedString;
bookg.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:bookg animated:YES]
A quick search would have given you an easy answer. For example, this post.
Simply set the font of the UITextfield you want to a [UIFont italicSystemFontOfSize:].
try this link see accepted answer and also check TTTAttributedLabel library
Bold one Word
now you want only textfbookpublisher in italic then pass it individually to next DissertationGen view
in DissertationGen controller's viewdidload method use following code
UILabel *lblpubl = [[UILabel alloc] init];
lblpubl.font = [UIFont italicSystemFontOfSize:18.0];
lblpubl.text = your variable which contains textfbookpublisher's text;
now use lblpubl as you wish

SSCollectionView SSCollectionViewItem - no Items displayed

I ran into difficulties with SSCollectionView and SSCollectionViewItem.
First of all I'd like to get it initialized from IB. But that won't work for me.
I have a SelectFooViewController which is:
#interface SelectFooViewController : SSCollectionViewController { ... }
and am using it as filesOwner of the corresponding XIB.
SelectFooViewController* selectFooVC = [[SelectFooViewController alloc]
initWithNibName:#"SelectFooViewController" bundle:nil];
But since it wont work I had to initialize its properties inside viewDidLoad() myself.
Furthermore I am not able to display anything except the backgroundColor of my SSCollectionViewItems. What I want is a textLabel and an image .
- (SSCollectionViewItem *)collectionView:(SSCollectionView *)aCollectionView itemForIndexPath:(NSIndexPath *)indexPath {
SSCollectionViewItem *item = [[[SSCollectionViewItem alloc] initWithStyle:SSCollectionViewItemStyleImage reuseIdentifier:itemIdentifier] autorelease];
SSLabel* label = [[SSLabel alloc] init];
[label setText:#"foo"];
item.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"foo.png"]];
item.textLabel = label;
[label autorelease];
return item;
}
I can confirm that the delegate methods (for determining the number Of rows, sections and such) are implemented and working as expected. But my items are all empty - but react onclick with the expected popup.
Does anyone see an error in what I did? - Thanks...
EDIT: I was also not able to display a local image by changing SSCatalog project
I just figured out, that I have to set the frame of each property (textLabel, detailTextLabel and imageView) myself. That fixed it.
When you create instance SelectFooViewController just insert this line
selectFooVC.view;
or
selectFooVC.view.hidden = NO;
And then add it to the view.
This is because the view is not initalised until you explicitly access it. Hence your items are loaded only when you click it and not immediately. You can call it a hack but i don't call it one. :-)

UITableViewCell holding a UIWebViewCell with Dynamic Height and a Loading Animation

I am currently trying to nest a UIWebView (among other elements) into a custom UITableViewCell subclass.
I need to dynamically determine the size of the cell (using heightForRowAtIndexPath) but for some reason when I do it like so, the height always gets printed as 0:
UIWebView* wv = [[[UIWebView alloc] init] autorelease];
[wv loadHTMLString:body baseURL:nil];
[wv setNeedsLayout]; //I don't think these are necessary but I tried anyway.
[wv setNeedsDisplay];
CGSize wvSize = [wv sizeThatFits:webViewBounds];
NSLog(#"WVHEIGHT %f", wvSize.height); //THIS IS WHERE IT PRINTS.
CGFloat retVal = 10.0f;
retVal += 50 > wvSize.height ? 50 : wvSize.height;
retVal += 2 + 15 + 10;
return retVal;
Now, if I do that exact same calculation using the cell.webView that I have access to in cellForRowAtIndexPath, it returns a non-zero value. However, I'd really like to avoid loading an entire cell just to figure out how tall it should be...
Additionally, UIWebView is very slow at rendering text (and it is unfortunately not negotiable that I use UIWebView), so I was wondering if there's a way to tell it to display the typical Apple "rotating gear" activity icon until it has its text fully loaded and ready to render.
I would recommend hiding each UIWebView until it is done loading, and showing a loading indicator instead. I would then make a dictionary with keys that match the tags, and for each entry in the dictionary, I would store the size of the UIWebView.
Make your controller conform to the UIWebViewDelegate protocol, and use the following code:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSString *output = [webView stringByEvaluatingJavaScriptFromString:#"document.getElementById('this').offsetHeight;"];
[self.webViewHeights setValue:[output floatValue] forKey:[NSString stringWithFormat:#"%f", webView.tag]];
}
After that, add code to hide your loading view and display your UIWebView, then call a table reload. In your cell height method, just check the correct array element for your UIWebView height.
Edit:
It seems I left out the important part!
OK, so, to create non-visible UIWebViews, you just need to create them, but not actually add them to a view. For example, you could do something like this in your viewDidLoad method:
UIWebView *newWebView = [[UIWebView alloc] initWithFrame:newFrame];
[newWebView loadHTMLString:body baseURL:nil];
newWebView.tag = 1;
[self.webViewDictionary setObject:newWebView forKey:#"1"];
Then in your table code, say something like
NSString *tagString = [NSString stringWithFormat:#"%d", indexPath.row];
UIWebView *curWebView = [self.webViewDictionary objectForKey:tagString];
if (curWebView.loading == NO) {
CGRect newFrame = curWebView.frame;
newFrame.size.height = [self.webViewHeights objectForKey:tagString];
curWebView.frame = newFrame;
[cell addSubview:curWebView];
} else {
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorStyleGray];
[cell addSubview:activityIndicator];
}
I don't think sizeThatFits: is what you want to use.
sizeThatFits:
Asks the view to calculate and return
the size that best fits its subviews.
Your webview does not have any subviews, only HTML.
UIWebView has no init method of its own, so you probably should use initWithFrame: (from the UIView superclass) to set the size directly. You can set it to the size you want, which is the size of the tableView cell in this case.

Having Problem with dynamically created UITextField in iphone sdk

In my iphone app, I have created some UITextField in scrollView dynamically. And added one button in xib. On that button's TouchUpInside event, I opened UIImagePickercontroller to open photo library and taking selected image on UIImageView.
Now when modalview is dissmissed, values in my UITextField disappears.
How do I retain the UITextField values?
txt = [[UITextField alloc] initWithFrame:CGRectMake(10.0f, 30.0f, 200.0f, 30.0f)];
[txt addTarget:self action:#selector(keyDown:)forControlEvents:UIControlEventEditingDidEndOnExit];
txt.textColor = [UIColor blackColor];
txt.borderStyle = UITextBorderStyleBezel;
txt.autocorrectionType = UITextAutocorrectionTypeNo;
[fieldArray addObject:txt];
Using for loop I am adding txt to NSMutableArray fieldArray.
Here is the code where I fetch values from TextFields
NSMutableArray *insertValues = [[NSMutableArray alloc]init];
//Taking values from textFields
for (int i=1; i<=nooffields; i++) {
UITextField *tf = (UITextField *)[self.view viewWithTag:i];
NSLog(#"TF : %#",tf.text);
if (tf.text.length<=0) {
tf.text=#"";
}
[insertValues addObject:[NSString stringWithFormat:#"'%#'",tf.text]];
}
EDIT :
And also when I display values from database in this textFields and try to edit it. It gives me null values.
What may be the reason? If there any other alternatives? please help me
UITextField *textField=[[UITextField alloc]init];
[textField setFrame:CGRectMake(x,y, width, hight)];
[textField setBorderStyle:UITextBorderStyleRoundedRect];
[self.view addSubview:textField];
The information that your scrollview uses to get populated should be stored outside the scrollview, in a NSMutableDictionary for example. So everytime cellForRowAtIndexPath gets called it can retrieve the information from that source. So I advise you to store the UITextField's text within the dictionary. You can index it by its tag number. That way you won't loose whatever it contained.
I hope it helps you
Cheers
I finally got a work around for my problem.
I am temporarily storing my textField's values into database when presentModalViewController is called.
These values I retrieve back into the textFields on viewWillAppear.
This may not be a very efficient solution but it worked in my case.
Hope this helps someone.
Thanks for all your responses.