I'm programming a UIAlertController for a popover on the iPad. I know you can set the background colour of the ActionSheet like this:
myAlertController.popoverPresentationController?.backgroundColor = myColour
And you can set the text colour of the buttons like this:
myAlertController.view.tintColor = anotherColour
What I'd like to do though is set the colour of the horizontal separators between UIActions. I have looked at the popover's subview hierarchy and I can see that, internally, it uses a UICollectionView.
So how would I change the separator colour, be it:
a hacky way via the subview hierarchy? Or, preferably,
an official way that I can't see in the docs?
Thanks
There is no available property for UIAlertViewController for customising the separators
You have to go through the subview hierarchy
Related
I have set an backgroundImage for my navigationbar. This works fine. But I would like to have the navigationbar height to be adjusted to the background image. At the moment the width of the background images is also not set according to the screen size.
I tried setting the height of the navigationbar like described here. This shows a bigger navigationbar for like a second but then it shrinks to its default size again.
Does anyone know how to achieve what I want? Here is an example of what I want to achieve: image
Apple Documentation:
It is permissible to customize the appearance of the navigation bar
using the methods and properties of the UINavigationBar class but you
must never change its frame, bounds, or alpha values or modify its
view hierarchy directly.
To achieve the effect seen in the image you tagged, they are most likely using a collection view to layout their data and that image is part of the collection view's header. They made the navigation bar background color clear, but the image is definitely not part of the navigation bar itself.
Apple recommends to never change the frame of a navigation bar manually because it messes with the layout code of its subviews and animation methods.
You could either subclass the navigation bar and attempt to create something similar, or go the easier route and make the navigation bar clear (UIColor(white: 0, alpha: 1) not .clear otherwise it might show up incorrectly) and have an underlying view display the image (e.x. a collection view whos header extends to the top of the view controller).
This will allow you to adjust the image height and width freely without subclassing the navigation bar, and creating potential bugs.
You can make custom NavigationBar class.
It can be help you
https://developer.apple.com/library/archive/samplecode/NavBar/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007418-Intro-DontLinkElementID_2
In a UIViewController, I'd like to show two tabs in a UINavigationBar. I want the UINavigationItems to have similar behavior to UITabBarItems in a UITabBarController. I want the NavBar to be visible in both view controller tabs, and I want to change the color of the tab title in the navBar if the tab is selected.
Is there a simple and elegant way to conveniently set text/selectedText or image/selectedImage and create UINavigationItems that have behavior similar to UITabBarItems, including the ability to have the nav bar space the items out evenly, just like in a UITabBarController?
It would be great if I could set this like it can be done in a tabBar:
UITabBarItem *tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:titleBlack selectedImage:titleRed];
The goal is to have two tabs, that change color if they are selected and they would be evenly spaced across the bar. I know I could do something simple like add two items to a navBarArray, but in order to have them spaced evenly across the bar for all screen widths, how would I do that? Is there an elegant solution?
This example shows the first tab selected. If I select the 2nd tab, I want Tab2 to be red and Tab1 to be black. This is just text, but if I have to create an image to accomplish this, I will.
This question is not a duplicate of the many questions on S.O. that are referring to displaying both a UITabBarController and a UINavigationController in the same app. This is different because I don't want a UITabBarController(I already have one that does something else- but I don't want to overcomplicate my question)- I just want to mimic this behavior, inside of a UINavigationBar. Please please please do not tell me I shouldn't do it this way. That's just another way to say "I don't feel like helping you figure this out."
I've tried looking for clean, simple, elegant solutions. I haven't found any. A complete example would be appreciated. Thanks =)
I came up with a solution that works well enough for me. I created a custom label with 2 buttons and a view with a height of 1 to act as a separator. I moved the UITableView down to pin the top of it to the UIView You could easily add more buttons if you desire to have more than 2.
In the viewDidLoad method: self.navigationController.navigationBarHidden = YES;
In viewDidAppear method: [self.navigationController setNavigationBarHidden:YES animated:YES];
Create a custom UILabel, pin the leading, top, and trailing to the superView, and set the desired height constraint.
Create a custom UIViewwith a height constraint of 1 (to act as the visual separator between the custom Navigation Bar and UITableView, pin the trailing and leading edges to the superView, and pin the bottom space of the UIView to the bottom space of the custom UILabel. Set the desired color for the separator.
Create two UIButtons, drag them into the label, and set these constraints:
-pin the UIButton center Y's to the center Y of the UILabel
-pin Button1's trailing to Button2's leading edge to each other and to the horizontal center of the superview
-Pin Button 1's leading and Button2's trailing to the superView
-Pin the top of the UITableView to the bottom of the UILabel
Set the UIButton color to change when selected, and set their targets as you would with any UIButton
Add any missing constraints in case I forgot to mention some.
Here is what it looks like:
I'm trying to make an app with a toolbar that can be resized. Basically, the toolbar can alternate between being at the bottom of the view and being at the top. When a button is pressed, it switches from one to the other. The problem is that when it is at the top, I want the size of the toolbar to expand to accommodate the status bar, but I don't know how to do this.
I've seen some solutions for changing the toolbar size but they all seem static and not something that can be changed with the tap of a button. Any suggestions on how to do this? Perhaps a different solution altogether?
You can use a normal UIView and customize it so it looks like a UIToolbar, then just set constraints using AutoLayout and animate the height-constraint.
I have to create the following layout in iOS.
in android we could use a single EditText to create this.
But in iOS we need
An imageView for background
A text field for the text
An image view for search icon
In android this causes overdraw.
is there the same overdraw issue in iOS?
You can not do without following view combination
An imageView for background
A text field for the text
An imageView for search icon
best possible way is you can loop through the search bar subview and replace or modify the curent subview to create the custom search bar
and there is nothing like over draw because they are key component for drawing a view. if you need any specific clarification then let me know
Consider using UISearchBar.
Or UITextField with a border (set on its layer), placeholder text and a rightView (set to an image view) for the icon.
Apple ships an app named “Contacts” on every iOS device. On the iPhone and iPod touch, it has a very particular way of styling the area above the search bar:
How is this coloring accomplished? Specifically, how is the color only visible at the top of the table view, and not at the bottom? Setting the backgroundColor property of the table view or its backgroundView does not achieve the desired result, either.
I would just create a UIView with gray backgroundColor containing a UISearchBar at the bottom of it, and set that to the tableHeaderView of your UITableView.
Maybe it's another view in a UIScrollView? (If so, above contentOffset.)