SearchBar's UITextField paddings? - ios

I use UISearchBar inside of UITableView. And I need to set custom left and right margins of UITextField.
Marked with red line on the picture.
Xamarin or Swift example could be applied.

Usually, when you want to add a searchbar to table you do it this way:
Choose a UIViewController instead of UITableViewController.
Add a UISearchBar on top.
Add UITableView below.
Set search bar to fixed height via constraints in Interface Builder.
Set the search bar's left & right constraints you want. (In your situation it would probably be something like 20px to right)
However it's also possible to use search bar the way, you've implemented it.
If you've used section header for a search bar, then you can add those constraints programmatically. Set them in willDisplayHeaderView method. That's a more complicated approach though.
Personally, I would rather go with first approach since it's much easier to set constraints in IB rather than programmatically.

If you want to add padding around the text inside the textfield this is how.
The image however shows the red line outside the the textfield, I would nest the UITextField inside a view and add the inset to that view.

Related

iOS: How can I remove reference to sub-views?

I'm creating an app that has hundreds of view controllers in interface-builder. Each of these view controllers has a button with a code number. When the button is pressed I want the button to expand and show a few lines of text describing the code number. The problem is that the button is placed within a subview that acts as a frame for the button. Therefore, the expanded button size is going to be constrained to that subview and the text will be cutoff. Is there a way for me to programmatically remove the reference to the sub-view? I can do this in interface-builder, but like I said there are hundreds of these view controllers.
Instead I removing it you could expand the subView's and the UIButton's width. That would allow the button to expand as you'd like it to and you would not have to remove the subViews.

Space in the content of UITableView

Today I faced a weir bug in UITableView.
I have a UIViewController containing a UITableView. I also have a root viewcontroller, which will add the aforementioned UIViewController as a child.
Now when loaded, it shows a space between cells and the top border.
How can I fix that?
Try to deselect Adjust Scroll view insets option of the ComicsVC view controller.
First select ComicsVC item in the left window of your storyboard, then in the attributes inspector you will easily find this checkbox.
You have to set top position of UITableView to 0. Also you have to add constraints between UITableView and parent UIView.
This bug appears when you use translucent navigation bar.
That space shows up for grouped UITableViews, and is usually occupied by a section header. If you don't implement a section header, then the area will be blank.
If you don't have more than one section, go to the UITableView in the storyboard, show the properties, and change the style to Plain.
Hope this helps!

UIStoryboards, UITableViewControllers, and UIToolbars: Can't Place The Toolbar Where I Want

This breaking my head because I can't seem to find a way to do it. I want to put a UIToolbar directly on top of a UITabBar, but whenever I drag the component, it goes and gets added below a UITableViewCell.
This is what happens:
The toolbar should be below, on top of the tab bar, not below the UITableViewCell. These cells are dynamic, not static (if it matters).
Any help will be really appreciated!
EDIT: I just figured it's adding the toolbar as a cell rather than as another component. I can't seem to add the toolbar outside the table though. Uuuhhgh.
Start by creating a ViewController, not a TableViewController.
Drag out the TableView into the ViewController and resize it accordingly, then add the UIToolBar below it.
Hope it works.

iOS - Interface layout

I need to achieve the following interface layout:
The obvious path would be a table view, but how would I do the top player and the bottom button set doing that? Embedding buttons in a table view row is a little unsightly I'd say, any suggestions?
It looks like a composed hierarchy of UIViews to me. The topmost element is a custom UIView subclass whose subviews, in turn, are comprised of the appropriate controls. Next down, is a UIButton, then your UITableView (does it scroll? It looks like perhaps not.) Then another row of buttons (trash, etc.)
So, to summarize, your base view is just a UIView that you compose with subviews, including what I assume is a grouped UITableView in the middle. It will be easiest to layout in IB.
You can have multiple table views within a UIView. Or you can put the top and bottom controls in the table header and footer. A quick example:

UISegementController in top of UITableView

I would like to add a UISegmentController in the top of my UITableViewController, just like in the AppStore.
I have tried googleing this but either I am search for the wrong things, or too view have written about this.
How can I do this, keeping it in the top with a different design than the UINavigationBar.
For style add segmentCont.segmentedControlStyle=7; which is same as the picture style.
It may not be a UITableViewController. It might be just a UIViewController with a segment control at the top of the XIB and a tableview placed underneath the segment control. That way, you could scroll the table view without scrolling the segment control.
I believe that is a custom header cell for the tableview. You should start by created a custom header with your segmented control inside that.
I think that's a ToolBar with UISegmentedControl or just UISegmentedControl and UITableView under it. You can place them (UISegmentedControl + UITableViewController) on UIScrollView and disable scroll for UITableView. You should make appropriate contentSize for your scrollview.

Resources