MKMarkerAnnotationView title is not showing - ios

Why MKMarkerAnnotationView title is getting disappearing. Some times title is appearing when we rotate map. How to make MKMarkerAnnotationView title should always visible.

MKMarkerAnnotationView has a property titleVisibility that can be set to one of the values
.adaptive
.hidden
.visible
.adaptive renders the title when there is space to do so, which is the default behaviour. If you want to see it always, set it to .visible.

Related

Bar section in iOS is extended unnecessarily

In the image shared, the orange section is the bar section , which is having unnecessary height, I am not able to resolve this issue by myself.
the views are like this
Parent Controller = View Controller
Child views = green view, black tableview
Please help to correct the height of the orange bar.
Seems like you have enabled prefersLargeTitles.
Make it false in your viewWillAppear()
self.navigationController?.navigationBar.prefersLargeTitles = false
You can also disable it from the storyboard.
Select your Navigation Controller -> Navigation Bar -> Uncheck prefers large titles
it seems like you're using the largeTitles on the navigationBar,
var prefersLargeTitles: Bool { get set }
When this property is set to true, the navigation bar allows the
title to be displayed out-of-line and using a larger font. The
navigation item used to build the bar must specify whether it wants
its title displayed in the large or small format. Use the
largeTitleDisplayMode property to configure the title's appearance.
When the property is set to false, the navigation bar displays the
title inline with the other bar button items.
try to disable it by:
navigationController?.navigationBar.prefersLargeTitles = false
or you can do this as well:
navigationItem.largeTitleDisplayMode = .never
hope this helps:)
https://developer.apple.com/documentation/uikit/uinavigationbar/2908999-preferslargetitles

How do I center an annotation title?

So I have a map with annotations that represent bikes. All of them have a title, an image, and a button. The title is on the left side by default as far as I can say. Is there any way I can center the title?
You can set the textAlignment to center
yourTitle.textAlignment = .center

iOS 11 prefersLargeTitles with uibutton as title

As titled, I'm using a UIButton as the titleView in the navbar. Is there a way for me to make the UIButton larger along with the navbar? When I set self.navigationController?.navigationBar.prefersLargeTitles = true, what I got is this,
I can't find any documentation on this, so I played a bit. It seems in iOS 11, you won't be able to get that title to be a button and display large at the left.
Also, I ttied playing with the frame size of the button (added below). I was unable to increase the button size, no matter what I set the frame to.
To recreate, I set up a Single View project. I embedded the view controller in a navigation controller.
In ViewController.swift's viewDidLoad, I added this code:
let titleButton = UIButton(type: .roundedRect)
titleButton.setTitle("Hello Button!", for: UIControlState.normal)
let navController = parent as! UINavigationController
navController.navigationBar.topItem!.title = "Hello???"
navController.navigationBar.topItem!.titleView = titleButton
navController.navigationBar.prefersLargeTitles = true
This ends up looking something like your example.
IF I:
set .title to empty string, or remark the line out: navbar is stretched, and no title text shows (or title text set in Interface Builder shows)
remark out .prefersLargeTitles, or set it to false: the navbar is the normal height, the button displays, but no title text displays.
remark out the titleView line, AND:
leave the .prefersLargeTitles set to true: the title text displays large at the left, and the navbar's height is stretched.
set the .prefersLargeTitles to false: the title text displays in the top center, and the navbar is normal height.

Why does opaque style not work on SearchBar?

How can I make the search bar tint color full blue?
I've tried:
searchBar.opaque = true
also
searchBar.translucent = false
But it does not work. Why?
From the documentation on .opaque
var opaque: Bool { get set }
A Boolean value that determines whether the view is opaque.
...
You only need to set a value for the
opaque property for subclasses of UIView that draw their own content
using the drawRect: method. The opaque property has no effect for
system provided classes such as UIButton, UILabel, UITableViewCell,
etc.
Hence, the .opaque properties will have no effect on a native UISearchBar; therefor, in you're example above, searchBar.opaque has no effect.
Regarding the .translucent property, the documentation states:
var translucent: Bool { get set }
A Boolean value that indicates whether the search bar is translucent
(true) or not (false).
The default value is true. If the search bar has a custom background
image, the default is true if any pixel of the image has an alpha
value of less than 1.0, and false otherwise.
If you set this property to true on a search bar with an opaque custom
background image, the search bar will apply a system opacity less than
1.0 to the image.
If you set this property to false on a search bar with a translucent
custom background image, the search bar provides an opaque background
for the image using black if the search bar has UIBarStyleBlack style,
white if the search bar has UIBarStyleDefault, or the search bar’s
barTintColor if a custom value is defined.
Hence, to achieve a transparent background for your search bar, you need to set also a background image for it, which has been described previously in the following SO thread
Can't change search bar tint color to be transparent in iOS 8
Using Mike:s answer in the linked thread (Obj-C), we can adapt to swift according to:
searchBar.barTintColor = UIColor.clearColor()
searchBar.backgroundImage = UIImage()
searchBar.translucent = false
This should achieve a transparent search bar.

IOS:UITabbar item click again and again it is reducing the UITabbar button item size in IOS 7

I'm took the Tabbar viewcontroller in this ,I added the 5 item and .I given the image insects is (24,0,0,6).
All button images are added in xib [under the Bar item -->image]Please help.
Thanks.
Adding to a similar answer here:
iOS Tab Bar icons keep getting larger
Not sure if this is an iOS7 bug but I've noticed that image insets need to be balanced.
You have specified insets for top and right but:
if you set a top inset, in order to balance it, you need to set the negative of it to the bottom inset
if you set a right inset, in order to balance it, you need to set the negative of it to the left inset
So, instead of having image insets like (24,0,0,6), use balanced image insets such as UIEdgeInsetsMake(24,-6,-24,6)
Doing so should protect your tabBarItem image from getting whacked on every tap.
If this doesn't suit your requirements, then redesign your tabBarItem image so you can have balance insets or... no insets at all.
Here's the workaround for a bug I've encountered with UITabBarController's UITabBar. If I tap a UITabBarItem once after it's selected, the icon shrinks. What I'd like to do is disable touches. UITabBarItem only has a setting for isEnabled, which grays it out if I set it to false...not what I was looking for.
I used a derivative of this answer to figure it out. With a UITabBarController with 3 tabs, printing tabBarController.subviews, I saw 3 UITabBarButtons and a UIBarBackground. The origin of UIBarBackground's frame was always (0, 0), putting it at the front of the sorted array, so I really don't need to know what the subview is, just "where it is" and whether it will always be there. The UIBarBackground is always going to be at the front of an array of tabBarController.subviews sorted by frame.minX, so I just need to remove it from the front.
Solution
Here's what the extension looks like:
extension UITabBarController {
var buttonViews: [UIView] {
var tabBarButtons = tabBar.subviews.sorted(by: {$0.frame.minX < $1.frame.minX})
tabBarButtons.removeFirst()
return tabBarButtons
}
}
I also created a struct in my Constants file, so I don't have to remember tab names:
struct TabBarItem {
static let firstTab = 0
static let secondTab = 1
static let thirdTab = 2
}
...and finally, where to use it:
In viewDidAppear (NOT viewDidLoad), add the following line to disable the UITabBarItem that you don't want to disable, but not gray out:
tabBarController?.buttonViews[TabBarItem.firstTab].isUserInteractionEnabled = false
In viewWillDisappear, re-enable the tab, as follows:
tabBarController?.buttonViews[TabBarItem.firstTab].isUserInteractionEnabled = true

Resources