iPhone SDK: Adding text to a MKMapView - iphone

I just want to add some text to a MKMapView (dynamically in code). It seems like one way to go would be subclassing MKShape and defining a custom annotation (i.e. one without a pin or any other graphics) but I'm uncertain how to do it. Also, it seems like it might be possible to layer another control on top of the MKMapView that would allow me to add text.

Why not just add a UILabel as a subview of the map?

Related

string under Map Kit pin (mkannotationview image)

I am trying to set names under pins that are on a map. Each name should be specific.
I am not using default pins, hence each pin is a specific image.
I was thinking of generating some kind of image that would present the image of the pin and the name as a label under it. Then append the whole thing as the image of the mkannotationview. But this looks like a mess to me.
Is there a way I could possibly append a label under a mkannotationview?
Or should a make a custom mkannotationview?
Thank you for your time.
Starting with iOS 11, if you subclass MKMarkerAnnotationView, you get those texts below the bubble for free, including collition detections: the text is sometimes rendered more left or right, depending where there is some space left on the map.
The MKAnnotationView class is a subclass of UIView, so you should be able to subclass it fairly easily.
I would probably create a custom subclass, and have my subclass add a label as a subview of the MKAnnotationView. You might need to adjust the frame of the view to make room for the label you're adding.

Custom Look And Feel of a text field in iOS

I'm a beginner with Objective-C and have a question regarding creating a custom look and feel text box. I want to be able to create a text box area that has, for example a header with a label and different background color etc. where the text input appears. How does one go about doing such a thing in Objective-C? Is it a matter of just creating a custom class that has a UILabel with specific coordinates on top of the UITextBox? Let me know if someone can point me in the right direction. Thanks.
One option is to create a custom view that contains a UITextField and UILabel as sub-views. After that, the view can be re-used.
I highly recommend reading the View Programming Guide # Apple: http://developer.apple.com/library/ios/#DOCUMENTATION/WindowsViews/Conceptual/ViewPG_iPhoneOS/Introduction/Introduction.html
A related post on creating an aggregate custom view: .Net UserControl XCode equivalent
Here's one tutorial on creating a custom view:
http://www.raywenderlich.com/1768/how-to-make-a-custom-uiview-a-5-star-rating-view
You can also look at how other custom controls are built. Many of the controls at cocoacontrols.com are open sourced: http://www.cocoacontrols.com/
Use layer property of text field like
#property (nonatomic,weak)IBOutlet UITextfield *email;
so in implementation file or view did load method
self.email.layer.backgroundColor = [uicolor orangeColor];

How to change the UISearchBar from round to rectangular? [duplicate]

I'd like to change the appearance of the default UISearchBar. As an example, how would you recreate the search box in the Google iPhone app as seen below? How would you overlay an image to produce this effect?
(source: isedb.com)
Upon some investigating of possibilites to customize the search bar, I'm inclined to say this is a custom component that has nothing to do with UISearchBar, but instead recreates its functionality.
You don't need to subclass anything.
Create a new UIView that has the buttons and text field and then when then entire view is going to load do this:
[self.searchDisplayController.searchBar addSubview:customSearchBarView];
Make sure to set the new text field as the first responder so it has access to the keyboard.

Updatable, custom view on a UIToolbar

I want to make a small area to present some information in the middle of a UIToolbar and was wondering what the best way to do this is.
I need to show some text and a graphic, both of which need to be updated (around every 3 seconds) as new information arrives. The graphic is similar to the iPhone signal strength indicator, so it can be either custom drawn or selected from one of 3 graphics (low, medium, high strength).
I'll probably use initWithCustomView: to create a UIBarButtonItem, although I would like the view to be clickable (to allow the user to change the information shown).
What's the best way to make that view? Can I use a NIB, or do I need to do custom drawing in the view? What's the best way to update the buttons? I'm assuming that I'll have to remake the toolbarItems array each time and set it when the information changes. Is there a cleaner way to do this? Thanks.
Using initWithCustomView: sounds like a good way to go. You can create your custom view any way you want: with a NIB, by drawing it, even using images. It can also have its own subviews. It can be any object that inherits from UIView. (So, if you wanted, you could even make it actionable by using a UIButton, a custom UIControl, or a custom UIView with a gesture recognizer attached.)
You shouldn't have to remake toolbarItems (or, for that matter, do anything with it after you've added all your button items) if you just keep a pointer to your custom view UIBarButtonItem. It could be an instance variable. Then, to update the custom view, you could access it as you would any other view. I've never actually tried this, but I can't see any problem with doing it.
You sound like you had it mostly figured out. Hope this is helpful.
I needed the same solution and was hoping for some code examples from you. So I ended up doing it all in IB and the steps are here as follows:
Create UItoolbar in IB with no Items. (A Bar Button Item will be added again once you add the UIView)
Add UIView as subview of UIToolbar
Add UILabels to subview of UIView that is already a subview of the UIToolbar.
Create IBOutlets from UIToolbar, UIView and each UILabel and then you can reference the labels in your app.
I did set the backgrounds to clearColor so the text appears on top of UIToolbar without any box or borders.
And the text updates dynamically which was the desired outcome.
Hope this helps someone as this has been eluding me for a while.

iPhone dev: adding an overlapping label to the image

I'm trying to figure out a best way to implement the picture-editing capability shown in the native address book app on iPhone.
On the built-in address book, this is how the picture looks like before editing:
qkpic.com/2f7d4 http://qkpic.com/2f7d4
And after clicking edit, notice how "Edit" overlay is added and the image becomes clickable:
qkpic.com/fb2f4 http://qkpic.com/fb2f4
What would be the best way to implement something like this? Should I make the image a button from the beginning and have tapping disabled at first? If so, what steps are required to add an overlay/label to the image (in above example, gray border + the text "Edit" is added)
The easiest way is to use Interface Builder, create a container view, then add a UIImageView and UILabel as subviews to it. You would position and style the text and the image but set the UILabel to hidden. Make the whole container view respond to touches. It's easy to do since UIView is derived from UIResponder so all you have to do is override touchesEnded. Whenever you want to change the text label, just set the UILabel to hidden=NO.
There's more to it, however. Notice how the image has rounded corners? You'll want to override the UIImageView's drawRect method to implement a custom drawing routine to do that. There's lots of sample code around and it wasn't part of your original question so I'll stop here.