I've got a strange (and very annoying) bug while trying to horizontally centering some text within a UITextField.
I have placed a UITextField using Storyboard with plain-text (not attributed) setting the horizontal alignment to center. Text appears correct aligned (centered) in storyboard but gives different results for different versions of iOS and between simulator and real device:
Simulator iPad with iOS 7.0:
non-editing mode: centered
editing mode: centered
after leaving editing mode: centered
Simulator iPad with iOS 7.1:
non-editing mode: left aligned
editing mode: centered
after editing mode: centered
iPad Air with iOS 7.1:
non-editing mode: left aligned
editing mode: centered
after editing mode: left aligned
Setting the NSTextAlignmentCenter before or after setText has no effect.
Is this a bug in iOS 7.1? Does anyone got the same problem or even a solution for that?
I had the similar problem in iOS8. Look like an iOS bug to do with making the text selectable.
If you make the text selectable in the Storyboard, it all works OK.
If its NOT selectable in the Storyboard, it always left justifies.
My UITextView is in a table cell, and I found I can setSelectable:NO in cellForRowAtIndexPath and it still aligns correctly (centred in my case) with selectable on in the Storyboard.
Tested in simulator (iOS 7.1 and 8.1) and on device (iOS 8.1).
I had the same bug and this is my fix. For the UITextView, set its text alignment in code and call its method layoutIfNeeded(). I did that after setting the text, if that makes a difference to anyone.
I tested it on simulator for iOS 8.4 and Xcode 6.4. Hope it helps!
Related
While applying AutoLayout I have switched to Preview Mode On so Preview window is showing my design in iPhone 8,iPhone SE and iPad devices like this
now I want to zoom out so that no need to scroll Preview window Left and Right.
Pinch Zoom In/Out is available in MacBooks but i need it for mac mini
Any help would be Appreciated.
You have to double click in the white space area.
I've submitted my macOS app to App Store and it was rejected. They provided a screenshot and the layout was totally different from my development machine. I created the app using Xcode 9, on a MacBook Pro 13", late 2011, without retina screen, running MacOS 10.12. I asked them about their environment and they said they tested using MacOS 10.10.
I'm wondering why that is happening. I tested my app using Xcode, and also exporting it and running it directly. I didn't get any issue. Could that be something to do with auto layout?
My background is iOS, so maybe I'm forgetting something more intrinsic to the Cocoa platform.
This is the screen on Xcode, with auto layout constraints.
This is the screen, running outside xcode.
This is the screenshot sent by Apple in the review process
Thanks =)
I got an answer from this link: https://forums.developer.apple.com/message/265199#265199
I did some extra testing, using only this view hierarchy:
View
- Vertical StackView
- Horizontal StackView
- Custom View
- Button
Also I had the constraints:
Vertical StackView
- Center horizontally on screen
- Anchor/Margin to top
Custom View
- Fixed Height
- Fixed Width
This was suffiient to reproduce the issue.
From the debug code, I could see that the Custom View had correct size, Horizontal Stackview had correct size. Only the vertical didn't have the propersize. Looked like VerticalStackview was clipping its content.
I managed to get it working by:
1) Fixing height on Horizontal StackView with constraint
2) Changing hugging priority on Horizontal StackView
3) Change clipping resistance on Horizontal StackView
Seems that for some reason, on macOS 10.10, the stack views or auto layout is not working in the same manner. Seems the content is not being calculated in the same way. By forcing constraints in every child view I got it working.
I have developed a new app from scratch using Xcode 6.
I have built the app in the "Base" and I set the constraints for all iphones and works perfect.
When I run the app on iPhone 5 or iPhone 5S for iOS 7 I have a black space from the top of the screen but the app is fine for theses devices on iOS8. (I added all the launchimages for all iOS(7+8) and for all sizes.
This is a screenshot with the issue:
The problem was with the constraints of the ImageView. I remove them all and then I set the UIImageView to have equal width and height with the parent UIView. Then I set constraints to keep the UIImageView on the center - both vertically and horizontally.
I am new to Xcode 6 and Swift, so I was checking it out and crafting a simple app but I encountered several problems:
When I run my app the keyboard does not react to whenever I "press" (click since I am in the simulator) in the text field. That is, the keyboard does not show up.
The app's elements in the storyboard TOTALLY rearrange sometimes when I mess around with the width and height of the storyboard and choose an different device for the iOS simulator.
All my problems and (little) code I've written is as shown:
I would appreciate any tips/help you guys can give me!
Thank you in advance!
Jack.
I have had similar issue some times on simulator, use ⌘+K or Hardware > Keyboard > Toggle Software Keyboard to prompt keyboard.
When change width and height of storyboard, examine closely the the descriptions (width, height, portrait, landscape) in the popup, I suggest choose the width and height that matches your device and orientation.
Hope this helps.
It is because of auto layout. Here is a link to guide you through.
Auto Layout Guide
I'm new to Xcode and I'm having a problem between interface builder and iphone simulator
As you see below, I set the imageview size for simulator, but some buttons places are changed, button texts disappeared or even buttons disappeared.
http://postimage.org/image/w9ej1c3z1/
I just open a new project and add buttons like the image below, then run the project. Same thing again! I'm doing something wrong?
http://postimage.org/image/6gl55tehd/
xcode version is: 4.5.2
Ios simulator version is 6.0
Please make validate your design by clicking on "Apply retina 4 form Factor" button at the bottom of view controller upon selection...
if you click on that button, It will change to simulator size and you can check the design
It looks like your view is for a 4" screen but you are running in the 3.5" simulator. You will probably just need to play with the autoresize a bit to make it work correctly.
Your interface builder is set for the resolution of an iPhone 5. Your simulator is on the resolution of an iPhone 4S. In the Simulator menu bar select Device -> Hardware - iPhone 5 (Retina) and you will see your additional buttons.
Here is a pretty good tutorial which explains how to support both the iPhone 5 and <= iPhone 4S screen resolutions. Working with iOS 6 Auto Layout Constraints in Interface Builder