I have an app with a deployment target of iOS 9.3.
I have just upgraded to Xcode 9.0.1, and have noticed this issue across all simulator devices and my own iPhone7 device running iOS11. The issue does not impact devices running < iOS11.
I am initialising a left bar button item, with a custom font as follows (in viewDidLoad):
UIBarButtonItem *safeModeButton = [[UIBarButtonItem alloc] initWithTitle:#"" style:UIBarButtonItemStylePlain target:self action:#selector(toggleSafeMode)];
[safeModeButton setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:#"Sosa-Regular" size:31],NSFontAttributeName,
nil]forState:UIControlStateNormal];
[self.navigationItem setLeftBarButtonItem:safeModeButton];
self.navigationItem.leftItemsSupplementBackButton = YES;
Shortly after in another method, I set the bar button title as follows:
self.navigationItem.leftBarButtonItem.title = #"è";
The problem is, I am seeing the actual è text on the button, rather then the symbol which should be rendered. è for the "Sosa-Regular" font is a symbol.
I previously didn't have this problem prior to the Xcode9/iOS11 upgrade. I have tried explicitly setting the titleTextAttributes before I set the title, but it always just shows the è. It's as if the titleTextAttributes is not persistent or setting the title outside viewDidLoad resets the titleTextAttributes for the button. If I set the title text in viewDidLoad, it's all working ok.
Any ideas would be appreciated.
Found the answer to this after playing around for a while. Shortly after initialising the UIBarButtonItem, I set it to enabled = false.
As I only specified the title text attributes for UIControlStateNormal, it was not applicable for UIControlStateDisabled. Strange this only came up with iOS11. So adding this line fixed the problem:
[safeModeButton setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:#"Sosa-Regular" size:31],NSFontAttributeName,
nil]forState:UIControlStateDisabled];
Related
iOS uses standard (blue) tint color for all colored texts in MFMailComposeViewController. This is not good for me, as customer wants his company colors in app. How to change their color to orange?
I am asking specifically about colors of button icons (add image and bell image) and texts containing mail addresses. I already have navigation bar colors changed. In documentation, there is written:
The view hierarchy of this class is private and you must not modify it. You can, however, customize the appearance of an instance by using the UIAppearance protocol.
I have tried to use it, but it is not working (I might doing it a wrong way, as I do not know UIAppearance). This is what I have tried:
[[UIButton appearanceWhenContainedIn:[MFMailComposeViewController class], nil] setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
[[UILabel appearanceWhenContainedIn:[MFMailComposeViewController class], nil] setTextColor:[UIColor orangeColor]];
As Apple says: https://developer.apple.com/library/ios/documentation/MessageUI/Reference/MFMailComposeViewController_class/index.html
The view hierarchy of this class is private and you must not modify
it. You can, however, customize the appearance of an instance by using
the UIAppearance protocol.
Anyway, you can check this post:
Customizing automatic MFMailComposeViewController opened from UITextView
I got this problem too. Just use:
UIView.appearance().tintColor = .orange
This works fine but there is a flaw. The recipients text will change back to system tintColor(blue) when editing.
I'm using this piece of code to set the default font (Custom) for all my UIBarButtonItems:
NSDictionary *attributesBarButtonItem = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:#"ProximaNova-Light" size:18.0], NSFontAttributeName, nil];
[[UIBarButtonItem appearance] setTitleTextAttributes:attributesBarButtonItem forState:UIControlStateNormal];
NSLog(#"%#", [[UIBarButtonItem appearance] titleTextAttributesForState:UIControlStateNormal]);
However, it seems to be ignored as the font does not change, and NSLog returns (null). It's a bit confusing because its pretty much the same code I'm using to set the default font for all my navigation bars and it works fine for them.
The piece of code is placed in AppDelegate´s didFinishLaunchingWithOptions but I've also test it in other viewControllers (viewDidLoad) with exact same result.
Other strange behaviour I've noticed:
I've got a tab bar controller, and when I load any viewController with bar button items it doesn't work, but if I push another viewController it works (The font is changed to the selected one), and it keeps working even if that viewController is popped out, although it will stop working if another tab is pushed.
Any help to try to set a default font for the UIBarButtonItems would be appreciated. Thanks!
Is this your custom font ?
There could be few problems:
is the font in TTF format ?
if you click on the font in xcode is Target membership in right panel checked ?
did you add the font to project plist file ?
Also you should use UITextAttributeFont in the dictionary:
[UIBarButtonItem appearance] setTitleTextAttributes:#{UITextAttributeFont:[UIFont fontWithName:#"ProximaNova-Light" size:18.0]} [forState:forState:UIControlStateNormal];
I had a similar issue arise because I was creating the leftBarButtonItem before I set the appearance attributes. Swapping the order such that appearance was set first fixed the problem.
I have a UITextView with text in it, the View is in a UITableViewCell. I noticed that the font was not quite the same on iOS7 as with iOS6, noting it was set to "system" I decided to specify the exact font/size.
It appeared nothing happened so I thought I would do a better test (big font not used anywhere), like this in my "CellForRowAt....";
cell.newsItemDescription.font = [UIFont fontWithName:#"didot" size:20];
cell.newsItemDescription.text = newsDescriptions[indexPath.row];
In iOS6 it comes out like this;
In iOS7 it comes out like this;
It happens in just a few places in the app but it is very annoying, can't figure out why? I am fast getting to the point where I may use the iOS7 Font/ Size throughout the app.
Some extra info;
The UITextView is resized per cell along with the cell (using springs/struts, i.e. no Auto Layout) and HeightForRow...
The font was setup in Storyboard originally (as system)
This is the same on devices and Simulator
I have a strange behavior in iOS 7. Font is smaller than I expect, if I was set it in to the xib.
If I set font after setting the text it's works for me. Otherwise font is smaller.
Try this:
cell.newsItemDescription.text = newsDescriptions[indexPath.row];
cell.newsItemDescription.font = [UIFont fontWithName:#"didot" size:20];
I had the same issue today with UITextView, and while reading AlKozin's answer, I remembered something: somewhere, sometime I read that since iOS 7, the best practice to set font styles is to set them after the View has loaded. In other words, if I set everything in viewDidLoad: , nothing happens. You have to set up the font of your UITextView in viewWillAppear:, like this:
-(void)viewWillAppear:(BOOL)animated
{
self.myTextView.font = [UIFont fontWithName:#"Baskerville-Italic" size:18.0];
}
I ran into a weird bug (Xcode 7.2.1), where unchecking "Selectable" in IB was causing the UITextView to not adhere to the font settings specified through IB.
This is same issue I was facing.
Making UITextview "selectable" from storyboard will work.
Setting textview.font worked fine for me on iOS 7, but none of these answers, or other similar answers on other SO pages worked for me on iOS 8. The only way I was able to get it working was to use an NSAttributedString.
NSMutableParagraphStyle *pStyle = [[NSMutableParagraphStyle alloc] init];
[pStyle setAlignment:NSTextAlignmentCenter];
tv.attributedText = [[NSAttributedString alloc]
initWithString:text
attributes:#{ NSForegroundColorAttributeName: color,
NSFontAttributeName: [UIFont systemFontOfSize:fontSize],
NSParagraphStyleAttributeName: pStyle,
} ];
I've just started using AQGridView from Alan Quatermain more specifically, the SpringBoard demo..
The demo shows icons/tiles that consist of a UIImageView. I'd like to know how to use a custom UIView instead so that I can have an icon with text/button underneath.
I'm currently trawling through the code with no real luck in finding how my icons are created.
Any ideas/suggestions would be greatly appreciated..
Cheers.
Check out AQGridViewCell and, specifically, contentView property. This is similar to customizing UITableViewCell.
Have you checked out three20's TTLauncherView?
Although it is for the iPhone you might be able to adopt it for the iPad. It allows for an icon with text underneath. Though you might have to hack it for inserting a custom UIView in place of the image and text.
I found iOSGuy's tutorial helpful when working with TTLauncherView.
And here is an excerpt from iOSGuy's tutorial to show little bit about how it is setup/used.
TTLauncherView* launcherView = [[TTLauncherView alloc]
initWithFrame:self.view.bounds];
launcherView.backgroundColor = [UIColor blackColor];
launcherView.columnCount = 4;
launcherView.pages = [NSArray arrayWithObjects:
[NSArray arrayWithObjects:
[self launcherItemWithTitle:#"Google"
image:#"bundle://safari_logo.png"
URL:#"http://google.com"],
[self launcherItemWithTitle:#"Apple"
image:#"bundle://safari_logo.png"
URL:#"myAppController/myView"]
, nil]
, nil];
I'm using MPMoviePlayerViewController - with the player controls set to: MPMovieControlStyleFullscreen
I'm having a problem with some of buttons that are in MPMovieControlStyleFullscreen: forward, reverse, and fullscreen (the one with the arrows pointing at eachother).
I would like to either remove the forward, reverse, and fullscreen buttons or control what they do when the user taps them.
Thank you!
There isn't a way to customize the MPMovieControlStyle values provided by Apple. What you need to do is is turn off the Apple controls (MPMovieControlStyleNone) and then create your own custom controls. Apple is fine with you putting your own UIViews in to the hierarchy here, so you can get started with something like this:
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: YOUR_URL];
moviePlayer.controlStyle = MPMovieControlStyleNone;
UIView *movieView = moviePlayer.view;
[movieView addSubview: _movieControlsView];
[movieView bringSubviewToFront: _movieControlsView];
Where _movieControlsView was set up earlier in code or in IB.
Aesthetically, you can do what you want, but I would recommend sticking with something that looks like Apple's choices so as not to confuse the user. For the project I just finished, I created a transparent button the exact size of the movie player. Clicking the button fades in a control bar on the bottom with my custom controls. If one of the controls isn't clicked, the control bar fades back out again after a few seconds.
First off, MPMoviePlayerController is a little different than MPMoviePlayer*View*Controller, so some of these answers lead to problems when converting applications that were built in an iOS 4.3+ environment.
I've built some apps using MPMoviePlayerController that worked fine when built in iOS 3.2. When I rebuilt it with XCode 3.2.6, (iOS 4.3), the videos don't even play on the iPhone. I since fixed that by adding the MPMoviePlayerController instance to a subView, then presenting a modal (Player is a UIViewController) with the movplayer in fullScreenMode:
//from didSelectRowAtIndexPath
Vid *selected = [items objectAtIndex:position];
player = [[Player alloc] init];
movplayer = [[MPMoviePlayerController alloc] initWithContentURL:selected.vidURL];
movplayer.view.frame = player.view.bounds;
movplayer.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
[player.view addSubview:movplayer.view];
[self presentModalViewController:player animated:YES];
[movplayer setFullscreen:YES animated:NO];
[movplayer play];
[player release];
//movplayer is released inside - (void)exitedFullscreen:(NSNotification*)notification
This was done on account of the UINavigationBar being half cut off when rotating.
When I got to the iPad version of the app the modal option wouldn't work aesthetically. It was also having the UISplitViewController navBar and toolbars half cut off when rotating in full screen mode. So I tried implementing MPMoviePlayerViewController instead of MPMoviePlayerController. With this conversion, XCode gave me errors when trying to set:
movplayer.controlStyle = MPMovieControlStyleEmbedded;
The proper way to do this with a MPMoviePlayerViewController is:
movplayer.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
When the player is added as a subView, the pinch gestures will toggle the player between fullScreen and the size of your parentView (player.view.bounds) smoothly, as well as preserve the toolbars and navBars native to the parent.
//iPad version with a view (viewForMovie) inside the DetailViewController
movplayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[current vidURL]];
movplayer.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
movplayer.view.backgroundColor = [UIColor clearColor];
movplayer.view.frame = viewForMovie.bounds;
[viewForMovie addSubview:movplayer.view];
So these two examples show some workarounds for those who want to convert their iPhone or iPad apps to a newer iOS version.
Try setting MPMovieControlStyle of your MPMoviePlayerController object to MPMovieControlStyleNone