iOS 7 MPMoviePlayerController change name of Done button - iphone

In iOS 6 we change name of done button in MPMoviePlayerController next way:
id mpBarAppearance = [UIBarButtonItem appearanceWhenContainedIn:[MPMoviePlayerViewController class], nil];
[mpBarAppearance setTitle:#"ГОТОВО"];
[mpBarAppearance setTitlePositionAdjustment:UIOffsetMake(1.5f, 1.f) forBarMetrics:UIBarMetricsDefault];
[mpBarAppearance setTitlePositionAdjustment:UIOffsetMake(1.5f, 1.f) forBarMetrics:UIBarMetricsLandscapePhone];
Now in iOS 7 this crash app, under debbug it no raise exception and I cann't even understand why ?

It's because you can't use the appearance proxy to customise the title of UIBarButtonItems. Otherwise, all the bar buttons contained in the given parent would be named the same. You can customise other appearance parameters such as the background images, title position and so on.
The appearance proxy reference for UIBarButtonItem can be found here

Related

UIBarButtonItem appearance setTitleTextAttributes does not affects UIControlStateDisabled state

Our designer asked me to use specific color for text of disabled UIBarButtonItems. That code I've used to implement this:
NSDictionary* textAttributes = [NSDictionary dictionaryWithObject: [UIColor blueColor]
forKey: UITextAttributeTextColor];
[[UIBarButtonItem appearance] setTitleTextAttributes: textAttributes
forState: UIControlStateDisabled];
But it doesn't changed text attributes.
I've tried this code with Normal state, tried to chage background for UIControlStateDisabled buttons with setBackgroundImage and all thouse experiments works perfectly. But this single combination: setTitleTextAttributes and UIControlStateDisabled doesn't do anything.
Google didn't give me any relevant answer about that specific combination.
Does anybody know other way to change color of disabled UIBarButtonItem or way to make setTitleTextAttributes work for diabled items?
You have to set it for both control state Normal and Disabled.
(2015-11-18 -- As of iOS 9.1 you must still set both.)
It's working fine for me with iOS 5.1. Perhaps it was a 5.0 bug.

initWithBarButtonSystemItem:UIBarButtonSystemItemPageCurl not working

I am creating a barbutton item and adding it to my navigation controller toolbar
UIBarButtonItem *barButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPageCurl target:self action:#selector(pageCurlAction:)] autorelease];
And the barbutton item is rightly loading with the toolbar in my viewcontroller.Now, I push a new viewcontroller into my view and when I pop the viewcontroller, my barbutton item with the page curl shrinks and and the page curl image is missing on the barbutton.
I tried changing the
initWithBarButtonSystemItem
with
UIBarButtonSystemItemPlay, UIBarButtonSystemItemPause, UIBarButtonSystemItemFastForward
etc. But, it works fine with them. Its just the page curl icon thats not being loaded. Any reasons for this?
From the iOS Human Interface Guidelines:
In addition, you can use the system-provided page curl button in a toolbar (for more information, see the documentation for UIBarButtonSystemItemPageCurl in UIBarButtonItem Class Reference). The page curl button is not available for use in a navigation bar.
(Emphasis added.)
Even if you use a UIToolbar, this problem can appear. It turns out the order in which you do styling and adding of toolbar items matters.
In my case I had to change from:
[self.toolbar setItems:items];
self.toolbar.tintColor = [UIColor grayColor];
to:
self.toolbar.tintColor = [UIColor grayColor];
[self.toolbar setItems:items];
in order for UIBarButtonSystemItemPageCurl to start working on iOS 4.3

custom UINavigationBar background in MFMailComposeViewController

I have a need to use a custom background for the UINavigationBar in a MFMailComposeViewController. Previously I was using a category on UINavigationBar to achieve this throughout my app, but Apple specifically requests that you do not do this. Additionally this may or may not work in future versions of iOS that are currently under NDA.
I am now using a subclass of UINavigationBar to achieve the look I'm after in the rest of the app, but I can't see any way to use this with the MFMailComposeViewController. Any ideas?
Note: I'm aware of methods to do this in a future version of iOS, but this needs to be built against a current version (4.3) of the SDK.
I just ran across this -- you can dynamically inject the class a view controller uses using object_setClass.
#import <objc/runtime.h>
object_setClass(mailController.navigationBar, [YourNavigationBarSubClass class]);
You can customize the nav bar's titleView with a custom view using the code below. Expanding upon this idea, you may be able to resize the titleView to cover the entire navigation bar and use a custom background in that to simulate a custom navbar background.
The only possible sticky part I can think of is that you need to make sure the titleView sits behind the buttons in the toolbar.
Once you have your MFMailComposerViewController reference, here is the code to customize the titleView:
[self presentModalViewController:controller animated:YES];
UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(//set size to navbar size)];
[backgroundView setBackgroundColor:[UIColor colorWithPatternImage://your custom image ]];
controller.topViewController.navigationItem.titleView = backgroundView ;
[controller release];
The mail composition interface itself is not customizable and must not be modified by your application.
check apple reference for more info...
http://developer.apple.com/library/ios/#documentation/MessageUI/Reference/MFMailComposeViewController_class/Reference/Reference.html
but we can customizable the mail composition as given oin the above answer....
After some hacking and testing, still not manage to customize the button. But this is the closest I can get, by setting the tint color of mail controller.
Try accessing them through mailController.navigationBar.items, which is an array of the bar items.
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.mailComposeDelegate = self;
mailController.navigationBar.tintColor = [UIColor brownColor];
Although it would be nice to get more control over the appearance, I don't think there is a clean method. When you cant change it...hide it:
NSDictionary *attributes = #{NSForegroundColorAttributeName: [UIColor clearColor]};
[[UINavigationBar appearance] setTitleTextAttributes:attributes];

Using UISegmentedControl as button

In my code I am using a UISegmentedControl as a "button" with only ONE segment and the momentary property set to YES. In versions of the SDK prior to iOS 4, this was not a problem, but it appears that now iOS 4 requires that there be at least 2 segments. The following code throws an exception:
NSArray *titles = [NSArray arrayWithObject:#"Button Title"];
myButton = [[UISegmentedControl alloc] initWithItems:titles];
and now in Interface Builder you cannot even create a UISegmentedControl with less than 2 segments. It logs the following error when building:
"The number of segments property of a segmented control must be greater than or equal to 2."
I'm kinda stumped. Any work arounds for this? I tried to create a UISegmentedControl with two buttons and then remove one programmatically and that "works" as it doesn't cause the app to crash. I get a button in iOS 3 and nothing in iOS 4. Any ideas?
Have you tried this:
[myButton removeAllSegments];
[myButton insertSegmentWithTitle:#"Press this" atIndex:0 animated:NO];
Really strange. It still works fine for me both in iOS4 simulator and device (this is a real working snippet from my code):
NSArray *laterContent = [NSArray arrayWithObjects: #"Maybe later", nil];
UISegmentedControl *later = [[UISegmentedControl alloc] initWithItems:laterContent];
CGRect frame = CGRectMake( 20,
98,
self.alert.bounds.size.width/2 - 30,
30);
later.frame = frame;
later.selectedSegmentIndex = -1;
[later addTarget:self action:#selector(laterAction:) forControlEvents:UIControlEventValueChanged];
later.segmentedControlStyle = UISegmentedControlStyleBar;
later.tintColor = [UIColor colorWithRed:130.0f/255.0f green:74.0f/255.0f blue:54.0f/255.0f alpha:0.8f];
later.momentary = YES;
later.alpha = 0.9;
It's not exactly a code-related solution but: I hit a similar issue and ended up drawing my own similar looking resources in Photoshop. It was not terribly difficult to do and removed a particular bad "code smell", IMO.
I found if you have a previous project with a single-segment UISegmentedControl, you can open both that project and your new one in Interface Builder and drag (or copy/paste) the single-segment UISegmentedControl to your new view controller. It will work fine in both your app and Interface Builder, just don't change the number of segments from 1 to anything else as it won't let you go back. I'm using Xcode 4.6.2 and iOS 6.
The editor in Interface Builder won't let you change the number of segments to be less than 1, but you can make a segmented control in IB by editing the .xib xml manually.
Right click on the .xib containing the segmented control
Choose Open As -> Source Code from the popup menu.
Find "<segments> which is the beginning of the xml array of segments. The whole thing should look like:
<segments>
<segment title="Segment 1 Title"/>
<segment title="Segment 2 Title"/>
</segments>
Just delete <segment title="Segment 2 Title"/> so there is only one segment element.
Right click the .xib again and choose Open As -> Interface Builder - iOS to go back to interface builder.
You should also probably set the segmented control to "momentary" mode.
I don't get any errors compiling or running this. Of course, this is a hack, and may break things in some circumstances or in a future iOS release.
Well two possibilities:
1) Create a button and the set background image as the single dot of the UISegmentedControl
If your SegmentedControl is a class variable just replace the #property
#property (nonatomic, retain) IBOutlet UIButton *button;
In the viewDidLoad-function add the following
-(void) viewDidLoad
{
[super viewDidLoad];
...
self.button = [UIButton alloc] init];
[self.button setBackgroundImage:[UIImage imageNamed:#"segmentedDot.png"] forState:(UIControlState)UIControlStateNormal];
}
2) Set the amount of segments to three of your UISegmentedControl and afterwards set the width to 20 - now only the dot in the middle will be shown.
Dont forget, if the user interacts with the UISegmentedControl, set the currentElement again to the second segment, else the dot will be in light grey instead of white state.
3) Place a button or a small view over the unwanted second dot of the UISegmentedControl in InterfaceBuilder. Make sure the backgroundcolor is even.
When you are using a button set the state for "user interaction" in attribute inspector to disabled. As type I would chose "custom" since you won't have some borders in your button ;)
Now male again sure, that always the first dot is the active Element.
However I think solution one should be the way you should go, since Apple thought something about it, when they disabled the 1-dot-SegmentedControl. Since you are using the Control as a button the Element you are looking fpr should be a button. ;)
There's no workaround in iOS 4. If you need this functionality, file a bug (enhancement request) at bugreport.apple.com.
You can also use removeSegmentAtIndex:animated:. If you create a segmented control in a storyboard or xib with two segments, you can remove one like this:
[self.sortButton removeSegmentAtIndex:1 animated:NO];

UIToolbar tint on iOS 4

just switched to iOS 4 on my iPhone 3GS and some of my apps broke.
One issue I had is that I had a UIToolbar with some buttons, tinted to pink, that worked well on the 3.1.3 OS. After upgrading to iOS 4, the toolbar was still tinted, but the buttons it contained were no longer affected by the tint. The toolbar was pink while the buttons were regular-blue.
Looked around for it on the net, but found no reference of such a thing.
Anyone knows what broke in the process?
(must be frank here - I knew the answer before posting, just didn't know how to load this data to StackOverflow. Thought the solution I found was valuable for others, so wanted to post it here. I'm new here, so please no harsh critics :) )
So eventually the problem resulted from, AFAICT, a change in behavior in the OS.
As stated the tint code worked before the upgrade and was written like this:
// Toolbar content
NSArray *items=[NSArray arrayWithObjects: ... ]; // PSEUDO CODE HERE
[toolbar setItems:items];
// Add tint
toolbar.tintColor = [UIColor colorWithRed:0.83 green:0.43 blue:0.57 alpha:0.5];
What I needed to do, was just reverse the order of things:
// Add tint
toolbar.tintColor = [UIColor colorWithRed:0.83 green:0.43 blue:0.57 alpha:0.5];
// Toolbar content
NSArray *items=[NSArray arrayWithObjects: ... ]; // PSEUDO CODE HERE
[toolbar setItems:items];
(If you created UIToolbar in Interface Builder, you can change it's tint there, and that applies for the buttons as well).
I guess the tint updated all buttons before iOS 4, while in iOS 4 it doesn't and when adding buttons, they check for existing tint. But this is just a guess. The solution works anyhow..
Hope this helps someone, and that I didn't violate any sacred SO rules...
Cheers!
Well, it seems more like an OS bug than a feature, since navigation bars do change their item's color when you set their tintColor.
We've found that if you change the item's style, it refreshes their color as a side effect. Doing the following worked in our case. The original buttons are bordered, so we change them to plain and set them to bordered again. You may do a more complicated and generic code that saves the current style, sets another one and then switchs back. I am just to lazy to do that. :D Anyway, you get the idea.
toolbar.tintColor = //<some dynamically obtained UIColor>
// Workaround to properly set the UIBarButtonItem's tint color in iOS 4
for (UIBarButtonItem * item in toolbar.items)
{
item.style = UIBarButtonItemStylePlain;
item.style = UIBarButtonItemStyleBordered;
}
Regards,
Rula.