View over tableView - ios

I have the following screen (image) which shows a side menu when the button is pressed the menu appears, plus I have a uitableview to show other things
my problem is that when the side menu appears the uitableview is resized.
How do I keep my uitableview intact?
I've been trying the next but I have not got anything:
#IBOutlet weak var Vmenu_usuario: UIView!
#IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
view.sendSubview(toBack:tableView)
view.bringSubview(toFront:Vmenu_usuario)
}

If you want to delete White space view over tableview
uncheck the option 'Adjust Scroll View Insets'.
more detail: Empty white space above UITableView inside a UIView
Hope this hellp.

Related

InputAccessoryView with custom view created in IB

I've read a lot of material on this topic but most of them create custom view programatically.
Is it possible to use InputAccessoryView with a custom view created in IB? In storyboard I've added textInputView, inside which I've added text view and send button etc as seen in the screenshot below.
I've following code so which removes Table View for some reason so I can't get it working. I've added tableview in the storyboard.
I've shown here only InputAccessoryView related code.
class InputAccViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
#IBOutlet weak var tableView: UITableView!
#IBOutlet weak var textView: UITextView!
#IBOutlet weak var textInputView: UIView!
// other code
override var canBecomeFirstResponder: Bool { return true }
override var inputAccessoryView:UIView {
get{
return self.textInputView
}
}
override func viewDidLoad() {
super.viewDidLoad()
textInputView.removeFromSuperview()
// other code
}
// other code tableview delegates etc...
}
Left screenshot is with the accessory view code which doesn't show table view. If I comment out accessory view related code it does show table view as in the right screenshot.
Seems you might be constraining the UITableView's bottom to the textInputView's top. When you are setting the textInputView as the inputAccessoryView of the UIViewController this no longer works as expected. When setting the textInputView as the inputAccessoryView make sure you constraint the bottom of UITableView to the bottom of UIViewController's view.

Swift: stop image inside scroll from moving up and down

I am working on a sample to display images inside scroll. The image is loading fine but then it allows me to drag the image up and down inside the scroll. I would still want to be able to move right and left (horizontally), but the image should be fixed from moving vertically.
The scroll view and the image constraints are set to the top, bottom, left and right as those of the main view.
What am I doing wrong?
This is my code and storyboard settings
import UIKit
class Image2ViewController: UIViewController, UIScrollViewDelegate {
#IBOutlet weak var scrollView: UIScrollView!
#IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.scrollView.contentSize = (imageView.image?.size)!
}
}
and these are my storyboard settings for ScrollView and ImageView. The top 2 are for the scroll and other 2 are for the image.
Adding this line in the viewDidload solved the issue:
self.automaticallyAdjustsScrollViewInsets = false

swift bringSubViewToFront

I have a bottomView with opacity set to 0.65, and embedded in that View I have 5 buttons - which also gets the 0.65 opacity attribute - but How do I make the buttons get rid of the opacity?
I want the buttons to be very clear
I have tried to make outlets of the View and the Buttons and set the buttons to the front - view, but it doesn't change the appearance of the button??
#IBOutlet weak var bottomView: UIView!
#IBOutlet weak var findVejOutlet: UIButton!
#IBOutlet var superViewOutlet: UIView!
#IBAction func findVejButton(_ sender: Any) {
superViewOutlet.bringSubview(toFront: findVejOutlet)
}
override func viewDidLoad() {
super.viewDidLoad()
settingView()
}
func settingView(){
bottomView.bringSubview(toFront: findVejOutlet)
}
If you set the opacity of a view to a value of less than 1, it makes all the contents of a view partly transparent (including subviews). You can't change that, and opacity has nothing to do with the front-to-back ordering of the views.
You either need to make the parent view fully opaque and the non-button subviews partly transparent, or remove the buttons from the translucent view and instead put them in the common parent view.

Swift ScrollView In UITableViewCell not scrolling

I am new to swift and am trying to add a UIScrollview to a custom UITableViewCell. I can't seem to get the scrollview to scroll in the simulator though. I have tested both vertical and horizontal scrolling.
Here is the code for my custom UITableViewCell
import UIKit
class CustomTableViewCell: UITableViewCell, UIScrollViewDelegate {
#IBOutlet weak var winLoseValueLabel: UILabel!
#IBOutlet weak var dateLabel: UILabel!
#IBOutlet weak var newTotalLabel: UILabel!
#IBOutlet weak var locationLabel: UILabel!
#IBOutlet weak var playersLabel: UILabel!
#IBOutlet weak var playersScrollView: UIScrollView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
self.playersLabel.text = nil
//self.playersScrollView.contentSize.height = 1000
self.playersScrollView.contentSize.width = 1000
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
func addLabelToScrollView(str : String) {
if self.playersLabel.text == nil{
self.playersLabel.text = str
}
else{
self.playersLabel?.text = self.playersLabel.text! + "\n\(str)"
}
}
}
My playersScrollView outlet has been properly connected to the scrollview in my storyboard. As far as I can see from all of the tutorials and sources online, I should just have to set the contentSize width or height (larger than the view area) to get it to scroll, which I have done in the awakeFromNib function.
Any ideas why this is not working in the simulator? Secondly, ideally I would like to have a vertical scrolling scrollview in the table cell, but I thought that the table view's vertical scrolling might have been interfering with the scrollview, so I changed it for horizontal scrolling for testing, which also didn't work.
Can you have a vertical scrollview in a vertically scrolling UITableView, or will the table view scrolling interfere too much with the scrollview?
Ok, it turns out that the constraints on my playersLabel, which is a subview of playersScrollView, was the culprit, although I am not sure why. I adjusted the constraints on the label and that allowed the horizontal scrolling to work.
The vertical scrolling still did not work, so I had to override the touchesBegan and touchesEnded methods in the scroll view so I could disable/re-enable the scrolling of the table view.

How to align content inside UITableViewCell for different screen sizes?

I have build a custom table cell:
class CustomTableViewCell: UITableViewCell {
#IBOutlet weak var streetLabel: UILabel!
#IBOutlet weak var cityLabel: UILabel!
#IBOutlet weak var priceLabel: UILabel!
func loadItem(#street: String, city: String, price: String){
self.streetLabel.text = street
self.cityLabel.text = city
self.priceLabel.text = price
}
}
Result on iPhone 5:
Result on iPhone 6+
As you can see the left side of the cell is displayed correctly, it sticks to the left. However the right side should stick to right but it does not. So here is my question:
How can the width of the cell be set to the width of the tableView so that the cell has the same width as the screen?
How can I make the right side actually stick to the right of the table cell?
UITableViewCells are always the with of the UITableView they are in so there is noting that you need to do.
Based on the screenshot you posted, it doesn't look like you are currently using autolayout to position your labels. What you'll need to do is just add a constraint from the right of your price label to the right of the cell. Then when the cell grows, your label will keep the same distance from the right edge of the cell.
Your constraints for the top labels should then look like this.

Resources