I have a label and a button on my screen. The button is aligned to the label via the auto layout baseline setting. When I run the app on an iOS 7.1 simulator, this is what happens:
Notice how the button's background (light blue) is all the way at the top of the screen. Tapping on the Button's text does nothing, but tapping on the light blue square trigger's the button's action.
Why is this happening, and how can I fix it?
This looks like it is a bug in iOS 7.1 when aligning buttons with attributed text via their baseline.
There are several ways to fix this:
Use iOS 8: When I tried the same exact behavior on iOS 8.4 simulator, everything worked properly.
Don't use an attributed string.
Align via the center instead of baseline.
Related
I'm developing an app for a customer that is only used by a small company. This app has a login screen with two text inputs for username and password.
Specs:
Xcode v11.3.1
iPod touch iOS 13.3.1
Swift 5
The user interface was built using the Interface Builder of Xcode. I set the border style of both UITextFields to .roundedRect and they look fine in Interface Builder:
But as soon as I'm testing the app on my iPod touch the UITextFields have an annoying bottom border (or bottom line) of the tint color of the text field:
The lines are red because I've set the tint color of the text fields to red. The only solution (that is clearly not the best one) is to set the tint color to UIColor.clear for both text fields. Then the lines are disappearing. But then the blinking cursor of the text fields are also invisible while editing the text.
I tried a lot of different things like setting the border color of the layer (textfield.layer.borderColor = UIColor.clear.cgColor) but nothing worked out so far.
I also searched the web for similar problems, but it seems that I'm pretty alone with this problem. Any help is appreciated!
I've run into an interesting situation with a UIWebView. In Interface Builder, I set all four constraints to equal the margins and filled the webview with content. It works exactly as you'd expect.
An issue occurs when I rotate the webview. The webview rotates but in doing so, it reveals an grey background color. This isn't a color that I've set. In fact, I set the parent's view to have a black background color to match the webview content.
Here are my constraints for reference:
I'd appreciate any guidance on how to make my webview will the entire border or at least, manually change the grey color. Much thanks!
Note: This only occurs in the simulator. I haven't tried this on a device yet.
Ack ... it was the background view that was the culprit. The simulator didn't pick up my color changes. I never did a clean on them. I tested today and was able to change the grey color to the one of my choosing.
I am having issues with a specific view on my storyboard. The button and textview don't show in the right place when using the ipad. It works perfect for the iPhone, however. I am using one storyboard for the both of them. (Not one each) Here is a screenshot for what it is showing and the blue rect is for where the textview should be and the red is for where the GPS button, which is visible to the left, should show. Any ideas? I have tried setting and reseting the constraints, but it has had zero effect.
Thanks
I have an application with some custom positioned bars, and as such I'd like to change the standard vertical alignment of the button text. I've tried setting
[buttonItem setTitlePositionAdjustment:UIOffsetMake(0, -22) forBarMetrics:UIBarMetricsDefault]
but nothing changes. Oddly, if I set a horizontal offset, the button moves just fine. It appears only vertical alignment changes are not being respected. Is this a bug on iOS 7? Am I misunderstanding something about the API? I see no documentation saying that the vertical alignment is ignored.
(example project showing the issue)
Unfortunately setTitlePositionAdjustment:forBarMetrics: doesn't appear to take effect. The best workaround I found was to use a UIButton instead, which can be done right in Interface Builder.
Add a UIButton to the UIBarButtonItem and set the font or image, size, etc.
In the Attributes Inspector, set the UIButton's control alignment to right
Hook the button back up to whatever actions you need
I am having issues with UIButton with background images. When clicking on a button when running the code in simulator and in iPhone 4s and 5, a button seems to be selected even when I press an area outside the button
I have a very simple UI with an image, followed by another image (Login), followed by 3 custom buttons (Facebook, Email and Signup) and an image after that at the very bottom.
Note -
1. I have each button size (width and height) equal to the size of the background image. So if the background image is say 100 by 20, the button would be 100 by 20. Also, I have Autolayout checked and the image to AspectFill the UIButton in the IB.
I have a UIView within the Superview. All the UI elements (images, UIbuttons with background images) are placed in the UIView.
I have constraints on the UIView for width and height, so that it remains the same in iPhone 4s and 5. I also have constraints to ensure that the UIView is horizontally and vertically centered.
Within the view, I have constraints on each UI element's (images and UIbuttons with images) width and height, so that it remains the same in iPhone 4s and 5. I also have constraints on each elements Y location. So, I have a constraint that the first image is X distance from the UIView's top line. Then, I have a constraint that the first button is Y distance from the image on top. Then, I have a constraint that the second button is Z distance from the first button above it. I, then, have a constraint that the bottom-most label is A distance from the bottom line of the UIView. And I have a constraint that the third button is B distance above the bottom-most label. The idea is to ensure that all these elements are in the center of the screen in iPhone 4s and iPhone 5 (since the UIView will move to the center due to the constraints on it and the UI elements within it will move to the center along with it since their constraints are relative to the UIView).
The project supports iOS 6, 6.1 and 7.
I started developing and testing using iPhone 4s. The buttons seemed to be working fine on it. Then I connected iPhone 5 and, on compiling, I found that the buttons' clickable area and the buttons' background image did not overlap anymore. I re-connected iPhone 4s, cleaned the project, built it again and ran it (both on the simulator and on the device) to find that the buttons did not work anymore. On clicking on an area outside the button, the buttons were getting selected. What was also strange was that in some cases, when I touched a button (ie. Facebook), the button below it (i.e. Email) was getting selected.
So, in summary, it worked fine in iPhone 4s. On connected, iPhone 5, it seems that the buttons stopped working properly. On reconnecting iPhone 4s, the buttons no longer functioned properly. I tried removing all the UI elements and restarting the build (in same view controller in the same storyboard), tried creating a brand new view controller in the same storyboard, but with no luck. I have had to start the project all over again to have it function in iPhone 4s. So, to me, it seems that something is corrupting the storyboard, to an extent that it cannot be fixed again!
I have highlighted the UIView in gray for your reference.
Please see the images for reference -
Basic screen with UIView grayed out and no touch
Basic screen with UIView grayed out and trying to click Facebook button -
Basic screen with UIView grayed out and trying to click on the non-clickable image below the Signup button -
Not sure if anyone has faced such problems But, I would love to understand it and fix it now since it is a reoccurring issue and do not want to face it when most of my project is complete as it seems to completely corrupt the storyboard, leaving me to start the project all over again!
Please help.
Did you try calling sizeToFit method on all the buttons?