Hide UIButton title when using autolayout - ios

Hey I'm learning developing in XCode with Storyboard and I have an UIButton with custom image. Before I developed without Autolayout but then I read about it and decided to try it. My problem is that the button has a custom image and it shouldn't display a title, only the image. When I don't use Autolayout everything works just fine (only image is displayed). But when I turn Autolayout on, it resizes my picture and pushes it to left and shows button title next to the image. How can I display only the image using Autolayout? Has this something to do with intrinsic content size??

Try my answer:
button.titleLabel.hidden=YES;

Try to:
button.autoresizesSubviews=NO;
Or:
button.titleLabel=UIViewAutoresizingNone;
Or:
button.imageView.autoresizingMask=UIViewAutoresizingNone;

Related

UIbutton stretch when clicked unexpectively

I am trying to modify a frame work and have encountered the following problem.
I have replaced one of the button image in the framework's xib file with my own one. The image itself is approximately 20Wx20H but I have set the button size to be 40Wx40H so that the clickable area is larger than the actual image.
When the VC is displayed, I see the image to be normal 20x20 aspect ratio. However, when I clicked on the button, it stretches to 40x20 and goes back to default upon release. I was wondering if there is a UIButton parameter that I can disable which was enabled by the framework somewhere? I have done a search on the buttons in the code and could not find anything relating to stretching the button. So I am guessing somewhere in IB there is my solution?
Below are the images for the button when touch down or not touched down.
Have you tried the following?
button.imageView.contentMode = UIViewContentModeScaleAspectFit;
Also are you using autolayout? If yes, what are the constraints?

iOS ImageView not filling screen and Button not on the bottom of screen

I'm new to iOS. I'm trying to achieve this layout in the app. I placed an ImageView and Button like that on the StoryBoard but when I run the app, the ImageView doesnt fill the screen and the Button is not in the bottom. How do I accomplish this?
You can watch this video , this is the best for me about auto layouts.
And the easiest way is Add Missing Constraints click here!
Set your UIImageView to scale to feel in atribute inspector and make sure about your autosizing should be like this.
You have to set constraint in your InterfaceBuilder.
More Info here:
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithConstraintsinInterfaceBuidler.html#//apple_ref/doc/uid/TP40010853-CH10-SW1

iOS - images stretched in stack-view

Here is my status I created stack-view with two sub views --> vertical and horizontal stack-view
the horizontal view contains 3 button
check image below
my issue when I set background to button its stretched as appear in image
my tries to fix this issue ,
1- set view mode to aspect-fit
2- increase spacing between button
3- set fixed width and height to one of buttons as all obey
but unfortunately all my tries doesn't work , any one could guide me to fix my issue thanks
Have you try to use SetImage Instead of BackgroundImagethat will fix the issue else use the proper image with proper size that you want to implement based on your requrement. see the following difference between setImage and SetBackgroundImage
Here you need to change your image size with your stack view's button image that will be fix your issue and for using stack view following is a good link: https://www.raywenderlich.com/114552/uistackview-tutorial-introducing-stack-views

Xcode UITableView image does not align properly on simulator

I am working on a project on Xcode7.3 using swift using autolayout. I am stuck with an problem with the UITableview not displaying properly on the simulator.
I created a ViewController and dragged a TableView into ViewController. Then I dragged a UIView and UIImage ontop of that TableView (To display as a header image). I also dragged a UIImage onto the prototype cell. They are all aligned in the center horizontally and vertically. However, when I run the app, they don't show in the middle of the screen.
As shown in the UITableView_Problem Image, the images are offset to the right. What is also weird is that when I rotate the screen, the scrollbar on the right does not go all the way to the right. The images appears to be in the center of the screen if I consider where the scroll bar is the end of the screen. But that doesnt make sense because the bottom bar items spans the full width of the screen.
However, if I create a UITableViewController from the story board instead of dragging a TableView onto a ViewController, I do not have a problem at all. (Image3)
It is frustrating because I wanted to add a text field for keyboard at the bottom of the screen just like the comment section in Instagram app. And after hours of searching, it appears that the only way to do that is to drag a tableView onto a ViewController. i stack imgur com JC5Pw png
Could anyone please assist? Much appreciated
Blockquote
note: I dont have a developers account yet so I cant check on an actual device
You are designing your interface in the wRegular/hRegular (or universal) size class. You will need to be very good about your constraints or develop a layout for the wCompact/hRegular size class for iPhones in portrait mode. You can change this by selecting here the blue part on the bottom of your storyboard
Thanks Dan for your prompt response! I added constraints to everything except for the tableView. Dont know what I was thinking as I have been troubled by this bug for a few days. Everything works fine after the tableView constraints was set!

UIDatePicker alignment inside static UITableView doesn't line up in storyboard vs simulator

I'm trying to learn how to embed pickers into table views and am starting off nice and simply with a static tableview where I've inserted a UIDatePicker within it.
Unfortunately I'm seeing odd behaviour with how the UIDatePicker aligns within the cell. If I line everything up nice and centred within the storyboard then when i run in the simulator i find the picker displays lower than centred and so looks messy. In the end by eye I've had to add padding to the cell beneath the picker in the storyboard to get it looking reasonable within the simulator when running. As shown in the following images.
Anyone any ideas why the storyboard layout isn't being honoured, or whether there's something I can change which would make them behave themselves better?
Apologies for the image resolution size.
layout of picker and cell in the storyboard
outline of my tableview in the storyboard
picker and cell shown in the simulator
Ok I eventually fixed this... i tried using some auto constraints having snapped the picker to the centre of the cell, sadly this didn't seem to help.
I then cleared the constraints and used the align button to add constraints for horizontal and vertical center in container. Added these constraints and now the picker is behaving consistently between the storyboard and the simulator.
Not sure why when adding it centred using the blue guidelines it didn't default to this sort of behaviour without the constraints but now I know.
Thanks to anyone who took the time to read my question.

Resources