UIButton Title not showing inside UIStackView - swift

I created a UIStackView with a UIImageView and a UIButton. The text inside of the UIButton won't show. I can tell that autolayout works because the background and the selection of my UIButton both work properly.
The title always disappears when I have the constraints on. I set the image to 0/0/0/0 without margins and aligned the button to the image's edges.
Has anyone run into this or knows how to fix it?

At the end I simply used a UIView. I don't know what made me use the UIStackView but I guess it's not made for overlaying objects.

Related

Adding image to UIButton makes it unclickable

I am learning to navigate and use the features of Xcode right now and I don't understand why adding an image to a UIButton through the Attributes Inspector makes the UIButton unclickable. When adding the image, it also resizes the button on the storyboard. I can't seem to find any answers online. Could somebody explain why this behavior occurs?
Before adding the image to the UIButton:
After adding the image to the UIButton:
Edit: and preferably how to fix it :D
The unclickable scenario you described is literally impossible unless you deleted everything in the connections inspector tab. In order for the image not to resize you should use autolayout in the bottom right. Set a constraint on width and height.

I have a UIButton subclass that I have set an image to in IB, and strangely about 1/3 of the button won't respond to touch! What's going on?

As described, I have a UIButton subclass, that I am designing in IB. I have set the button subclass to a UIView, and set an image to the button as well. I have set a UILabel beneath the image, attempting to give it the Finder look. Everything works great, except for the fact that the right 1/3rd of the image won't respond to touch!
It is the strangest thing. The button bounds are set to encapsulate the entire image, but that right 1/3rd won'r respond.
Has anyone seen this before? Does anybody know what's going on?
Thanks

Resizing UIImageview with a UITextview using UIGuesture

I'm new in Iphone. I have an UITextView inside a UIImageView . Now I need to dynamically resize the UIImageView so that its textview also change its size dynamically. Moreover I can move this UIImageView with UITextView around the screen. If any one knows this using UIGuesture please help me.
Any help would be appreciated
If you are looking at resizing the UIImageView object, look at the UIPinchGestureRecognizer. It will have a property called scale that you can use to change its size.
As for the UITextView object that is the subview, you can look at autoresizingMask property inherited from UIView. Set it appropriately so that the text view scales in response to its super view.
For moving the image view, you can use the UIPanGestureRecognizer. You can get the translation using translationInView:. Use this to modify the center of the image view object. This should move the image view as you drag your finger around.
I hope you've gone through the guide. Let us know if you face problems implementing this and put some code so that we can guide you in the right direction.

Adding a background image to a UILabel

I'm attempting to add a UIImageView to the subview of a UILabel, but for some reason, I'm unable to have it as the background as this will cover the actual label text.
I don't want to set the UILabel's background color as because it will repeat as a pattern:
[self setBackgroundColor: [UIColor colorWithPatternImage:[UIImage imageNamed:#"someBg.png"]]];
Looking at the number of subviews to a raw UILabel it seems like the text isn't a UIView so adding the subview to index 0 won't help either.
I need the text to be ON TOP of the image background.
Any ideas?
Your options:
Wrap the label and the background image view in another container view.
Write your own label class that supports background images.
Anyhow I solved this by inheriting UITextField and adding the subview to that. This works since there's actually a UILabel subview within this control and adding it behind it naturally solves the problem.
Also, I disabled user interaction so that it behaves like a label.

UIButton - unwanted background well

I'm creating UIButtons (type = UIButtonTypeCustom) with a custom background drawn by an artist; unfortunately UIButton is adding an unwanted 'well' effect around the backgroundImage (as specified via setBackgroundImage). Is there a way to disable the well? It's not a simple drop shadow, so messing with the CALayer properties doesn't seem to help. I realise I could use UIControl, but that's considerably more work, since I need to handle the label subview myself, and get the artist to produce highlighted versions of the artwork - UIButton is doing all that nicely, if I could only disable the well effect.
Put your image inside a UIImageView, and then position your UIButton on top of it. Use the "custom" style, which has no UI to it at all and is totally invisible.
If you want to change ("highlight") your button image when the button is hit, just change the image contained in the UIImageView in whatever method your UIButton targets.