I use this to make the size of the button dynamically, everything is ok, but when I scroll, sometimes the title of many buttons disappear, when I scroll again the title appears. Any help please.
This's the image when the text disappears.
This when the text appear again.
Try to add a layer to your button:
yourButton.layer.insertSublayer(shapeLayer, below: yourButton.titleLabel?.layer)
shapeLayer is the shape's button.
Check this response if it's useful for your problem
Related
hi i want to resize my button width by text length when adding title right insets
i tried set Constant 100 and Priority 1000 and it work perfect
but when i add image and right insets,
button title show like this
"apple...omputer"
and i tried this
button.invalidateIntrinsicContentSize()
and
button.sizeToFit()
still not work and still show "..." in my button text
and i tried to add width after set button title in viewdidload, but still not working
button.frame = CGRect(button.frame.origin.x, button.frame.origin.y, button.frame.width+50, button.frame.height)
Storyboard buttons
Resizing button because text became larger
Please look at screenshots above. You need to set your insets and set right constraints. Autolayout does it for you.
I am writing an application for an event my organization is hosting using Swift. I have an image with the floor layout and want to add buttons to select locations (such as bathrooms, entrances, exits, emergency sections, etc) so that people can click them and information about the location pops up.
I currently have an imageview with the floor layout within a scrollview to allow the user to zoom in and out of the image. When I try to add buttons to the scrollview they don't stay relative to the image when zooming in and out, nor do their size change. I have tried adding constraints on to make the location stay the same when zooming in and out.
It also won't let me relocate the button on the storyboard to be a subview of the imageview. Looking up similar solutions says to add the button programmatically as a subview of the imageview but then it'd be really hard to put the 100+ buttons in the right location. Any suggestions as to how to go about this?
you have no other choice instead of adding by code.. because from code you can add as subview of image view , whereas Storyboard wont add buttons as subviews of imageView, but it will add buttons as subview of Scroll View
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.
I have a storyboard with a UIScrollView taking up the entire iPhone screen. I have a label at the top for the title, and then a textview below that which has text loaded into it from a .txt file. However when I scroll, it scrolls through the large body of text with the title staying put at the top of the view, even though the label is based in the scrollview rather than outside of it. Any ideas how I can fix this?
Thanks!
textView has its own scrolling method built in, so your textView will scroll independently of your scrollView. Create the title within the textView or set text view not to scroll in Interface builder and use your scrollView
I have a UiView which contains a UiWebview, UIButton and a UITextView as its elements.
I add this UiView to a UIScrollView and resize the frame so that the text view is not visible. When i click the button i resize the view to display the entire UIView including the UItextview.
The problem is , the text view appears below the view when i resize the frame. When i click expand it covers the text view too.
When view is first added i want the view to display just the webview and the button and when button is pressed it should display the text view.
How do i achieve it? Has it got to do with view hierachy?
you should enable clipping on the UIView .
edit:
I wouldn't resize the view. Instead I would just change the hidden-property on the textview. If you want to add some animations later then you can modify the alpha-property as well.