I've got a few buttons with text inside. If i run the app on an iOS 10 device, it works and shows the text fine. But running the app on iOS 9 the text inside the button is like "squashed" or "compressed"(the text on version 9 is missing the top and bottom part of the text). I'm not sure why this is happening, I've tried messing around with the hugging and compression settings on the UI Builder, but this hasn't really fixed the problem.
Not sure why it works on 10 but not on 9....The image above shows what the text looks like on iOS 9 ONLY!
I'm just seeing if this is happening with anyone else? or if anyone knows how to solve this problem?
I appreciate any help given! Thanks in advance!
You have to use "adjustsFontSizeToFitWidth" property of titleLabel of your button
Example:
myButton.titleLabel.adjustsFontSizeToFitWidth = YES;
There are a few possibilities:
The height of the button during runtime could be wrong. Try setting a border to the button, run and observe the button outline to see if the height is correct.
myButton.layer.borderColor = UIColor.black.cgColor
myButton.layer.borderWidth = 1
If the height is wrong, it means the constraints could be incorrectly set up.
Another possibility might be contentEdgeInsets, titleEdgeInsets properties of the button having larger than intended top and bottom values.
Related
Warning: leading or trailing horizontal alignment before iOS 11
I am getting above warning during compilation on Xcode 9.1 on one of the scenes in a storyboard file. There are other storyboards (with deployment target iOS 10.0) and yet the warning is shown to this specific scene on a specific Storyboard file.
The warning gets suppressed if I change deployment target to iOS 11.0 on the scene where warning is shown but I don't want to do that.
Has anyone come across this case?
For me the problem was in using trailing leading alignment on UIButton itself.
Safe area seems to be completely fine to use - it's backward compatible and it translates into proper super view margins.
But this feature is iOS 11 only, so use standard left / right alignment instead if you are targeting lower iOS versions.
Easiest way to find out which view is causing the problem is to search for contentHorizontalAlignment="leading" or contentHorizontalAlignment="trailing" in source code for .xib
Step 1:
View your offending storyboard as source code:
Step 2:
Replace all instances of:
contentHorizontalAlignment="leading"
with:
contentHorizontalAlignment="left"
Step 3:
Replace all instances of:
contentHorizontalAlignment="trailing"
with:
contentHorizontalAlignment="right"
Step 4:
Compile and watch warning disappear.
I find this approach easier when you have a ton of elements that need to be modified.
"leading" and "trailing" as 'contentHorizontalAlignment' value types were introduced with iOS 11. iOS 10 doesn't know about "leading" and "trailing" which is the reason for the warning.
In the build log, right before the word "warning", you will see an Interface Builder identifier in the form "xxx-yy-zzz". Copy and paste that into the Xcode search bar, and it will find the "offending" control for you. Click on the search result and it will take you right into the storyboard with the corresponding control selected. The rest of the problem can be resolved using the other answers.
I had this problem with a whole bunch of buttons that I needed left aligned with a little offset. I removed the storyboard alignment and did it like this in viewDidLoad with an array of the needy buttons.
func indentButtons(buttons: [UIButton?]){
for i in 0..<buttons.count{
buttons[i]!.contentHorizontalAlignment = .left
buttons[i]!.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0)
}
}
I'm posting here because I'm completely lost on this one.
I've searched all over the web, tried a lot of things myself, and searched weeks on this bug, but I can't find it.
So ever since iOS 11 (doesn't happen on iOS 10), everytime I press a button that activates the "show" segue in a UINavigationController the animation shows some weird padding at the top.
This padding disappears when the animation is finished.
I've changed the backgroundcolor of the superview to a red color, and the space you can see is indeed from the superview itself, so my guess is the whole UITableView is being moved down for some reason, although I'm not sure what exactly is the cause here.
(I'm using storyboard and AutoLayout constraints)
Another thing I noticed is that the spacing/padding you see is different on the iPhone X compared to the other devices (my guess is that it's the same height as the (non)safe area at the top? Again, not sure.
I don't think code is necessary to be provided here, as I wouldn't really know which part causes this behaviour (and there's a lot of code that I can't share for reasons..).
Any suggestions/help on how to fix this would be deeply appreciated!
Here are some examples:
iPhone X running iOS 11.1 (also happened on 11.0)
iPhone 8 gif
EDIT: I should add, some things I already tried:
tableView.contentInsetAdjustmentBehavior = .never
Setting headerviews to 0
tableView.setContentOffset(0, animated: false)
Playing with the translucency settings of the UINavigationBar
AutomaticallyAdjustContentInsets is set to false
So, as suggested by Spenser-Arn, I played around with the constraints and the Safe Areas, turns out, the safe areas where the cause of the issue.
Hope this helps other people as much as it helped me, and a big thankyou to Spenser-Arn!
Since iOS 11, when the UIWebView is full screen, a fake background appears on the status bar with the same color of the UIWebView background.
Anyone knows how to get rid of it?
Even adding the IUWebView to a storyboard and make it full screen will make the status bar background to appear
I've been trying to edit the size and some other properties of the UIWebView and none of them worked, but it's definitely something from the UIWebView.
Also tried to see all the subviews and it's sizes and didn't see anything strange.
Attached a screenshot, see the grey "statusbar", it disappears when scrolling, and doesn't appear if the UIWebView is not over that part of the screen.
I want it as on the second screenshot, only remove the fake background, not the status bar.
This happens because of UIScrollView new behavior to adjust the content inset to include safe area insets like the status bar.
To fix it, just set it to UIScrollViewContentInsetAdjustmentNever
[self.webView.scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
Since iOS 11 Beta 4 you can add this to your viewport and will also remove the fake statusbar
viewport-fit=cover
To do this entirely in HTML/CSS, viewport-fit=cover in the Viewport meta tag is the correct way to handle this.
But you'll also want to adjust your padding dynamically to handle the differently sized status bar on iPhone X with its notched camera/speaker.
Luckily, Apple exposed some CSS constants for the safe area insets, so you can take advantage of those in your CSS:
i.e., padding-top: constant(safe-area-inset-top);
I wrote a bit more about this scenario and the new features for iOS 11 and iPhone X: https://ayogo.com/blog/ios11-viewport/
Swift version:
webView.scrollView.contentInsetAdjustmentBehavior = .never
When my app launches, I see a white screen, instead of my launch image. I am using a storyboard, as required, and everything was working fine for about 2 months before this. I didn't change anything related to the image or storyboard either, it just started happening. I should mention that this started happening sometime after my first time uploading to TestFlight...but I doubt that is relevant. I have tried changing the constraints of the image to make it smaller than the bounds, and it still doesn't show up, so it isn't the size of the image. Again, I seemingly did nothing to have this start happening. Most of the questions related to my problem on stackoverflow have to do with the user not using a storyboard as required with iOS 9. Please help. Thanks.
UPDATE
I launched it on the simulator (iPad2) and the launch image for that was too small...there was white exposed above and to the right, I'm guessing I need to fix something in the storyboard but I'm not sure what.
UPDATE
I made a new storyboard and assigned the launch-screen config to it, and there is still a white screen.
I deleted the UIImageView and then inserted a new one with dimensions 200 x 200.
I added the image to the UIImageView.
I adjusted the constraints to the same values that I was using before.
Adding the image to the 200 x 200 UIImageView, before adding the constraints, seemed to be the key.
Make sure that one of the view controllers has the Is Initial View Controller checkbox checked in the Attributes Inspector in the right sidebar, that got me.
In project by default you LauchScreen.xib. Put your launch image there and set it’s top, bottom, leading, trailing constraints. Tap your project file and scroll down. There you will see: LauchScreen option and MainStoryboard. Set LauchScreen to your LauchScreen.xib. That’s it))
I have updated my device iOS to iOS 8 and now multiline label is not working. Its displaying very weird screen shot attached.
So please can you suggest me the solution.
I already set Number of lines =0 and it was working perfect in ios 7.
Not using Autolayout and story board.
This code help you.It works fine me.Edit your code according to need
UILabel *problem = [[UILabel alloc] initWithFrame:CGRectMake(40, 100, 200, 100)];
problem.lineBreakMode=NSLineBreakByWordWrapping;
problem.text=#"Please use this code it may help you it works fine for me";
problem.numberOfLines=0;
[self.view addSubview:problem];
Strangely enough, this fix doesn't work if you don't use all of it:
Set the line break mode to word wrapping (if that's the affect you want).
Set the number of lines to 0 (I had it set to 2 and it still didn't work).
Not sure if something changed here with the introduction with iOS 8 but my previous code (just setting the number of lines to 2) was working great on iOS 7.
Anyone else face a similar issue?
Do you use a custom font?Try changing the font.